黄瓜和水豚,单击非链接或按钮元素
我正在尝试使用 Cucumber/Capybara/Selenium 堆栈测试就地编辑器,但我的问题是编辑器是通过单击 div 而不是链接或按钮来激活的。我似乎不知道如何让水豚做到这一点。有办法做到这一点吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以通过
Capybara:: 单击某个元素元素.click
。我在web_steps.rb
中添加以下内容以单击 div。还有
Element.trigger('mouseover' )
似乎可以启用悬停,但不能与 Selenium 一起使用。您也很可能需要使用 Capybara 提供的
@javascript
标签来装饰您的功能/场景。You can click on an element via
Capybara::Element.click
. I add the following for this in myweb_steps.rb
to click on divs.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.除了能够像 @Jim Mitchener 解释的那样单击按钮元素之外,您还可以通过以下方式单击文本的一部分:
此辅助函数与
find(selector).click
执行相同的操作,它找到文本元素。我发现这篇文章非常好,它解释了您可以在cucumber中编写的不同类型的步骤。
Besides being able to click on button elements like @Jim Mitchener explained, you can also click on a part of a text in the following way:
This helper function does the same thing as
find(selector).click
, it finds the text element.I found this article very good, it explains different types of steps you can write in cucumber.