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

本文介绍了解决WebDriver无法点击页面上特定按钮的问题,通过XPath定位替代不唯一的class和id选择器,确保了自动化测试脚本的稳定性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


先看截图:
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();同样可以解决问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值