Element is not currently visible and so may not be interactedwith 解决方法

来源:互联网 发布:数据科学家待遇 编辑:程序博客网 时间:2024/05/12 16:21

先看截图:
Webdriver <wbr>Element <wbr>is <wbr>not <wbr>currently <wbr>visible <wbr>解决方法
在Firebug中对应的html源码,见高亮显示。
Webdriver <wbr>Element <wbr>is <wbr>not <wbr>currently <wbr>visible <wbr>解决方法

如果用:
driver.findElement(By.className("cancelBtn")).click();
或 driver.findElement(By.id("save_btn")).click();
就会报“Element is not currently visible andso may not be interacted with”错误

解决方法:
思路: 使用findElements遍历,input标签,然后找到share按钮对应的 索引值,然后再操作。
List<WebElement>element=driver.findElements(By.tagName("input"));
for(WebElement e:element)
{
System.out.println(e.getAttribute("id"));
}
element.get(78).click();
至此 问题解决。

问题更正: 此种问题的关键是在于用className和id都不唯一所以找不到对象,改为:
driver.findElement(By.xpath("//input[@value='Share']")).click();同样可以解决问题。
0 0