Skip to content

Instantly share code, notes, and snippets.

@nakajima
Created February 5, 2009 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save nakajima/58876 to your computer and use it in GitHub Desktop.
Save nakajima/58876 to your computer and use it in GitHub Desktop.
Run Javascript with Selenium. Easily.
module SeleniumHelpers
# Execute JavaScript in the context of your webrat's Selenium session.
def run_javascript(javascript)
selenium.get_eval <<-JS
(function() {
with(this) {
#{javascript} // This code will be run in the context of the current window
}
}).call(selenium.browserbot.getCurrentWindow());
JS
end
end
When /^I click "(.*)"$/ do |text|
run_javascript <<-JS
jQuery('*:contains("#{text}")').click();
JS
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment