Selenium:如何使 WebDriver 忽略“元素不可见”?错误?
我正在使用 Selenium WebDriver (v2.5.0)。当我使用 driver.click(...)
" 命令时出现此错误
Element is not currently visible and so may not be interacted with Build info: version: '2.5.0', revision: '13516', time: '2011-08-23 18:30:44' System info: os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.38-10-generic', java.version: '1.6.0_26' Driver info: driver.version: RemoteWebDriver
在浏览器中,当我将鼠标悬停在某个元素上时,被单击的元素变得可见。有什么方法可以检查是否存在有些东西是可见的还是不可见的?
I'm using Selenium WebDriver (v2.5.0). I get this error when I use a driver.click(...)
" command
Element is not currently visible and so may not be interacted with Build info: version: '2.5.0', revision: '13516', time: '2011-08-23 18:30:44' System info: os.name: 'Linux', os.arch: 'amd64', os.version: '2.6.38-10-generic', java.version: '1.6.0_26' Driver info: driver.version: RemoteWebDriver
In the browser when I mouse hover on an element, the element being clicked becomes visible. Is there any way to check whether something is visible or not?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你可以通过行动来做到这一点。实现你想要的,使用Python Webdriver客户端,但是原理是一样的。
You can do it via actions. To achieve what you want, using the Python Webdriver client, but the principle is the same.
最好的解决方案是不使用 click() 方法,而是实现 Actions 并让 selenium (通过 webdriver)模拟鼠标在元素上移动以激活事件,然后使元素可单击/启用。激活该元素后,然后根据需要执行 click() 方法。我假设该元素已被禁用,使其首先无法单击。
建立您的元素,您还可以使用 RenderedWebElement ,它具有悬停()方法,然后您不需要创建以下 Actions 对象,但它可能无法工作,具体取决于应用程序如何使用本机事件设计。两者都尝试一下,看看哪个效果最好、最优雅。
创建新的操作 由网络驱动程序支持的对象
将光标移动到元素 - 这将“激活”您的元素以使其可单击
验证该元素现在可单击或“已启用”
现在执行单击操作
Your best solution is to not use the click() method but to implement Actions and have selenium (via webdriver) simulate the mouse moving over the element to activate the events which then make the element clickable/enabled. once you have activated the element, then perform the click() method as needed. I am assuming that the element is disabled making it not clickable in the first place.
Establish your element you could also use RenderedWebElement which has a hover() method then you wouldn't need to create the following Actions object however it may not work depending on how the application is designed with native events. Try both see which works best and is most elegant.
Create a new actions object backed by the webdriver
Move the cursor to the element - this will "activate" your element to be clickable
Verify the element is now clickable or "enabled"
Now perform the click action