Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capybara - unable to click a link

I am using Capybara 2.4.4 to click a link. The html is like this:

<a name="skiplink" id="skiplink" type="button" href="javascript:void(0);" onclick="skipForm(); return false;">salta</a>

Capybara command:

find("a", :text => "salta").click
find('skiplink').click

none of both works:

Failure/Error: find("a", :text => "salta").click
     NoMethodError:
       undefined method `empty?' for nil:NilClass

I have copied-pasted the html from save_and_open_page output so it may be correct

I am using default driver (no selenium)

Thanks

like image 215
user1066183 Avatar asked Jul 23 '15 14:07

user1066183


1 Answers

Either of the following should work

click_on('salta')
find(:css, '#skiplink').click   # the :css is only necessary if you've changed capybaras default selector

your find("a", :text => "salta").click should work too -- however when using capybaras default driver (racktest) clicking on javascript links isn't going to work since the driver doesn't support javascript. You need to switch to a different driver (selenium, capybara-webkit, poltegeist, etc.) that supports javascript

like image 118
Thomas Walpole Avatar answered Sep 30 '22 06:09

Thomas Walpole