Out of the box, Cucumber contains a web step that allows you to easily click a link. But what if what you want to click is not a link, but some plain text like:
<h3 class='clickable-text'>Click me</h3>
Unfortunately, Cucumber doesn’t have a web step for such case, so Dustin and I had to do some digging around. We found in Capybara’s source code that Capybara’s Node::Finders::find() takes the same options as Node::Finders::all(), and it supports :text as an argument!
So, this is the Capybara code that would click the text above.
find('.clickable-text', :text => 'Click me').click