gpt4 book ai didi

ruby-on-rails - capybara ,selenium 交互隐藏或显示 : none css properties

转载 作者:行者123 更新时间:2023-11-28 20:05:05 33 4
gpt4 key购买 nike

我正在使用类似的结构:

<div class="edit" style="visibility: hidden;">
<a href="some_path" id="edit_item">Edit</a>
</div>

然后我将鼠标悬停在该元素上变得可见,但是我很难将此操作与测试(使用 cucumber 、 capybara 、 Selenium )进行交互。

我得到一个错误

Element is not currently visible and so may not be interacted with (Selenium::WebDriver::Error::ElementNotDisplayedError)

我尝试使用 Element.trigger(event)使用鼠标悬停,但它不适用于 Selenium ...我如何与这个元素互动?

最佳答案

我使用 capybara 的 execute_script 解决了这个问题:

When /^I hover element "([^""]*)"(?: within "([^""]*)")?$/ do |id,selector|
with_scope(selector) do
page.execute_script("$('#{id}').mouseover();")
end
end

When /^I click in hide element "([^""]*)"(?: within "([^""]*)")?$/ do |id,selector|
with_scope(selector) do
page.execute_script("$('#{id}').click();")
end
end

但此解决方案不适用于 css - display: none;

关于ruby-on-rails - capybara ,selenium 交互隐藏或显示 : none css properties,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7784849/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com