Posted about 8 years ago. Visible to the public.

Click on a piece of text in Cucumber / Capyabra

The step definition below lets you write:

Copy
When I click on "Foo"

This is useful in Selenium features where the element you click on is not necessarily a link or button, but could be any HTML element with a Javascript event binding.

The easiest way to get this step is to use Spreewald. If you would like to add it manually, here is the step definition:

Copy
When /^I click on "([^\"]+)"$/ do |text| matcher = ['*', { :text => text }] element = page.find(:css, *matcher) while better_match = element.first(:css, *matcher) element = better_match end element.click end
Growing Rails Applications in Practice
Check out our new e-book:
Learn to structure large Ruby on Rails codebases with the tools you already know and love.

Owner of this card:

Avatar
Henning Koch
Last edit:
about 7 years ago
Keywords:
Click, any, HTML, element, (div, img, ...), with, Selenium, non-button, non-link, element
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Henning Koch to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more