The direct code for the chapter is to simply call has_link? and then click_link action:
if page.has_link?('name') page.click_link('name') end
But this will not be the fastest solution, since Capybara will make two requests for the driver to get the item: first one in has_link? , and the second in click_link .
The best option would be to create only one request to get the item:
or
Personally, would I go with the has_link? implementation has_link? / click_link , since the second option does not verify that the element exists in only one place, and the third is too long.
Andrei Botalov
source share