这里为了定位checkbox,XPath写法如下。 //td[text()='bbbb vvvvvvvvv']/preceding-sibling::td/div/input[@class='hidden']
但是这个输入没有被捕获。 util "//td[text()='bbbb vvvvvvvvv']/preceding-sibling::td/div/", 元素定位。有什么特别的原因吗? 我想知道为什么这个 XPath 不起作用?
最佳答案
尝试 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);
关于java - 如果有多个子标签,前面的 sibling 将不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55268536/