在这里,要找到复选框,XPath的编写如下。 // td [text()='bbbb vvvvvvvvv'] / preceding-sibling :: td / div / input [@ class ='hidden']
但是未捕获此输入。 util“ // td [text()='bbbb vvvvvvvvv'] / preceding-sibling :: td / div /”,元素已找到。有什么特别的理由吗? 我想知道为什么这个XPath无法正常工作吗?
答案 0 :(得分:1)
尝试使用webdriverwait和任何以下选项。
选项1:
WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@name='id' and @type='checkbox']")));
element.click();
选项2:
WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@name='id' and @type='checkbox']")));
Actions action=new Actions(driver);
action.moveToElement(element).click().build().perform();
选项3:
WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement element1 = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@name='id' and @type='checkbox']")));
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();",element1);