Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to click_link with no text?

How can I click below link with Capybara's click_link method?

<a data-method="delete" href="/users/sign_out" rel="nofollow">
  <span title="Sign out" class="glyphicon glyphicon-off"></span>
</a>
like image 831
Marcin Doliwa Avatar asked Oct 08 '13 11:10

Marcin Doliwa


2 Answers

You could locate the element using its href attribute:

page.click_link('', :href => '/users/sign_out')

Note that the first parameter of click_link is the links text, id or name. We use '' since the text is blank.

Alternatively, use the find method to find the link using the href attribute (or any other attribute) and then click it.

page.find(:css, 'a[href="/users/sign_out"]').click
like image 189
Justin Ko Avatar answered Sep 21 '22 17:09

Justin Ko


Add id to link and use its id.

click_link('link_id')

More info here

like image 39
Peter Tretyakov Avatar answered Sep 21 '22 17:09

Peter Tretyakov