【发布时间】:2021-03-09 14:02:56
【问题描述】:
使用 selenium webdriver 测试按钮是否不可见,布尔值始终返回 true。
使用下面的代码并返回 TRUE,在网页中我可以看到 Add 按钮的 xpath。按钮不可见。
boolean present;
try {
//driver.findElement(By.xpath("//button[@id='add']"));
driver.findElement(By.xpath("//button[@id='add']")).isDisplayed();
present = true;
System.out.println("Add button is present");
} catch (NoSuchElementException e) {
present = false;
System.out.println("Add button is not present:" +e.getMessage());
}
xpath: addButtonxpath
【问题讨论】: