水豚,硒与隐藏或显示交互:无CSS属性
我使用类似的结构:
<div class="edit" style="visibility: hidden;">
<a href="some_path" id="edit_item">Edit</a>
</div>
然后我将鼠标悬停在这个元素上变得可见,但是我很难将此操作与测试交互(使用黄瓜,水豚,硒)。
我收到一个错误
元素当前不可见,因此可能无法与之交互(Selenium::WebDriver::Error::ElementNotDisplayedError)
我尝试使用 Element.trigger(event) 鼠标悬停时,但它在硒中不起作用...... 我如何与这个元素交互?
I'm using similar construction:
<div class="edit" style="visibility: hidden;">
<a href="some_path" id="edit_item">Edit</a>
</div>
Then I hover mouse this element become visible, but I have difficult to interact this actions with tests(using cucumber, capybara, selenium).
I get an error
Element is not currently visible and so may not be interacted with (Selenium::WebDriver::Error::ElementNotDisplayedError)
I tried to use Element.trigger(event) with mouseover, but it doesn't work in selenium...
How I can interact with this element?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我使用水豚中的execute_script解决了这个问题:
但是这个解决方案不适用于css - display: none;
I solved this problem using execute_script from capybara:
but this solution doesn't work with css - display: none;
为了将来参考,请记住
execute_script
< /a> 可以在 elements 中调用,它提供了 更好的异步保证:指定
visible: :all
是查找隐藏元素的另一种方法:也就是说,与隐藏元素交互可能会隐藏 UI 中不允许的实际问题用户执行交互,因此最好谨慎使用它。
For future reference, have in mind that
execute_script
can be called in elements, which provides better async guarantees:Specifying
visible: :all
is another way to find hidden elements:That said, interacting with hidden elements may hide real issues in the UI that won't allow a user to perform an interaction, so it's better to use it sparingly.