Cucumber 和 Capybara,单击非链接或按钮元素 [英] Cucumber and Capybara, clicking a non-link or button element
问题描述
我正在尝试使用 Cucumber/Capybara/Selenium 堆栈测试就地编辑器,但我的问题是编辑器是通过单击 div 而不是链接或按钮激活的.我似乎无法弄清楚如何让 Capybara 做到这一点.有没有办法做到这一点?
I am trying to test an inplace editor using Cucumber/Capybara/Selenium stack, but my problem is that the editor is activated by clicking a div and not a link or button. I can not seem to figure out how to get Capybara to do this. Is there a way of doing this?
推荐答案
你可以通过Capybara::Element.click
.我在 web_steps.rb
中为此添加以下内容以单击 div.
You can click on an element via Capybara::Element.click
. I add the following for this in my web_steps.rb
to click on divs.
When /^(?:|I )click within "([^"]*)"$/ do |selector|
find(selector).click
end
还有Element.trigger('mouseover')
似乎可以启用悬停,尽管它不适用于 Selenium.
There is also Element.trigger('mouseover')
which appears to enable hover albeit not working with Selenium.
您也很可能需要使用 Capybara 提供的 @javascript
标签来装饰您的功能/场景.
It is also very likely you will need to decorate your feature/scenario with Capybara's provided @javascript
tag.
这篇关于Cucumber 和 Capybara,单击非链接或按钮元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!