黄瓜和水豚,单击非链接或按钮元素 [英] Cucumber and Capybara, clicking a non-link or button element

查看:287
本文介绍了黄瓜和水豚,单击非链接或按钮元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用Cucumber / Capybara / Selenium堆栈测试一个内部编辑器,但我的问题是,编辑器是通过单击一个div而不是链接或按钮激活。我似乎不知道如何得到水豚这样做。是否有办法这样做?

解决方案

您可以通过 Capybara :: Element.click 。我在 web_steps.rb 中为此添加以下内容以点击div。

 当/ ^(?: | I)点击([^] *)$ / do | selector | 
find(selector).click
end

还有 Element.trigger('mouseover') 看起来启用hover即使不使用Selenium。 / p>

这也很可能是你需要装饰你的功能/场景与Capybara提供的 @javascript 标签。 p>

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?

解决方案

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

There is also Element.trigger('mouseover') which appears to enable hover albeit not working with Selenium.

It is also very likely you will need to decorate your feature/scenario with Capybara's provided @javascript tag.

这篇关于黄瓜和水豚,单击非链接或按钮元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆