如何在Rails 3中使用Capybara单击具有相同文本的第二个链接? [英] How to click on the second link with the same text using Capybara in Rails 3?

查看:40
本文介绍了如何在Rails 3中使用Capybara单击具有相同文本的第二个链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在查看文件中,我有:

= link_to 'View', post
= link_to 'View', comment

在规格文件中(我正在使用Capybara):

In a spec file (I'm using Capybara):

click_on 'View'

它单击第一个链接,但我希望它单击第二个链接。我该怎么办?

It clicks on the first link, but I want it to click on the second one. How can I do it?

推荐答案

可能有几种方法,但我通常会采用这种方式。

There's probably a few ways but I usually scope something like this.

within(".comment") do
  click_on("View")
end

也有可能/也可能有其他选择。我通常从黄瓜上做我的验收测试,所以我的步骤通常看起来像是

There's quite possibly/probably alternatives as well. I usually do my acceptance testing from cucumber, so my steps typically look like

When I follow "View" within the comment element

在其中我有一个步骤可以在注释元素内翻译 对该步骤本身进行有范围的调用(我认为这是内置在最新的capybara web_steps中)

Where I have a step that translates within the comment element to a scoped call to the step itself (which I think is built into the latest capybara web_steps)

这篇关于如何在Rails 3中使用Capybara单击具有相同文本的第二个链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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