We're hiring!

We're actively seeking designers and developers for our all three of our locations.

How to Click Text Using Capybara and Cucumber

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
Sivabudh Umpudh (10 Posts)

This entry was posted in Ruby and tagged , . Bookmark the permalink. Both comments and trackbacks are currently closed.

One Comment

  1. Posted October 24, 2012 at 2:19 pm

    This worked great for me thanks!