[英]In Selenium using Java the program is not clicking on the element (NoSuchElementException)
[英]Java selenium using xpath : NoSuchElementException
现在我正在使用 selenium(java) 进行浏览器测试。
但是,xpath 存在一些问题。 我试过下面的代码。
webDriver.findElement(By.xpath("//button[@onclick='addUserWf();return false;']")).click();
带 web 元件
<button class="btn-etc btn-object-add" onclick="addUserWf();return false;">...</button>
也许你可以参考,spring 引导打印:
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//button[@onclick='addUserWf();return false;']"}
我可以看到上面的元素(这意味着元素显示和可见),所以我无法理解。
补充:我试过这个,但结果是一样的。
webDriver.findElement(By.xpath("//button[@class='btn-etc btn-object-add']")).click();
有人知道这个吗?
试试下面的 xpath:
webDriver.findElement(By.xpath("//button[@onclick=\"addUserWf();return false;\"]")).click();
或者
webDriver.findElement(By.xpath("//button[starts-with(@onclick='addUserWf')]")).click();
在单击任何按钮之前使用 webdriver wait 总是很好的做法。
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath(XPATH)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.