How to click on the second link with the same text using Capybara in Rails 3?

前端 未结 7 938
北海茫月
北海茫月 2020-12-24 11:25

In a view file I have:

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

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

click_on          


        
7条回答
  •  无人及你
    2020-12-24 12:05

    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
    

    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)

提交回复
热议问题