Created
September 12, 2011 05:27
-
-
Save ches/1210639 to your computer and use it in GitHub Desktop.
Capybara selector/Cucumber step to click any element with given text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Brandon Keepers' "click on any element with given text" Capybara selector/Cucumber | |
# step pairing, adapted for Capybara 1.0+. | |
# http://collectiveidea.com/blog/archives/2010/08/03/clicking-any-element-with-cucumber-and-capybara/ | |
Capybara.add_selector(:element) do | |
xpath { |locator| "//*[normalize-space(text())=#{XPath::Expression::StringLiteral.new(locator)}]" } | |
end | |
When 'I click "$locator"' do |locator| | |
msg = "No element found with the content of '#{locator}'" | |
find(:element, locator, :message => msg).click | |
end | |
# Or a possible simplified alternative: | |
When 'I click "$locator"' do |locator| | |
find(:xpath, XPath::HTML.content(locator)).click | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment