先看截图:
如果用:
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();同样可以解决问题。