Click on a piece of text in Cucumber / Capyabra

Updated . Posted . Visible to the public.

The step definition below lets you write:

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 Show archive.org snapshot . If you would like to add it manually, here is the step definition:

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
Henning Koch
Last edit
Keywords
Click, any, HTML, element, (div, img, ...), with, Selenium, non-button, non-link, element
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2012-07-17 11:45)