java - 如果有多个子标签,前面的 sibling 将不起作用

标签 java html selenium selenium-webdriver xpath

这里为了定位checkbox,XPath写法如下。 //td[text()='bbbb vvvvvvvvv']/preceding-sibling::td/div/input[@class='hidden']

但是这个输入没有被捕获。 util "//td[text()='bbbb vvvvvvvvv']/preceding-sibling::td/div/", 元素定位。有什么特别的原因吗? 我想知道为什么这个 XPath 不起作用?

enter image description here

最佳答案

尝试 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/

相关文章:

java - 使用递归打印大小为 n 的所有二进制数

java - 填充 FlowLayout 的空白空间

Javascript 表单提交 - anchor 与按钮

java - Selenium:动态查找 CSS 选择器

testing - 计划采用 Watir 来满足我们的 UI 测试需求 - 它是正确的工具吗?

java - Scala Iterator 与 Java Iterator 的问题(类型转换噩梦): How to cast to Java from Scala?

java - 在 Pane 仍在运行的情况下更改发送到 JOptionPane 的 JPanel 的布局

html - 我需要帮助排除 mobile.css 上我的 style.css 的一部分

jquery - 组合两个Jquery插件: Not Working

python - 使用 Selenium WebDriver 将文件下载到特定路径