CapyBara Click Link Different Cases and Solutions


To click generic link whom text is not multiple times used:

click_link "Help"

To click generic link whom text is multiple times used:
Like show, destroy, edit links on your index page


first(:link, 'Show').click
first(:link, link_name).click

Click Link with id


 all('a').select {|elt| elt.text == "#tag1" }.first.click

OR
Which of the links do you want to click on? If it’s the first (or it doesn’t matter), you can do


find('#tag1').click
Otherwise you can do

all('#tag1')[1].click
to click the second one.

If  you have, nested html and link lies in


<div class=”item”>
<a href=”/agree/”>Agree</a>
</div>
<div class=”item”>
<a href=”/agree/”>Agree</a>
</div>

 


first('.item').click_link('Agree')
Advertisements

I am Senior Software Engineer. I love reading, writing, sharing,developing, hiking, movies, trips, mountains, brooks, hills etc.

Tagged with: , , ,
Posted in Capybara, Integration testing
3 comments on “CapyBara Click Link Different Cases and Solutions
  1. We can also use the following for select any first link if there is multiple links with the same name:
    e.g: In case of destroy link at Index page:

    click_link("destroy", match: :first)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

StackOverFlow
Categories
Archives
%d bloggers like this: