user1066183
user1066183

Reputation: 2584

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

Upvotes: 6

Views: 5137

Answers (1)

Thomas Walpole
Thomas Walpole

Reputation: 49870

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

Upvotes: 8

Related Questions