Created
February 5, 2009 17:59
-
-
Save nakajima/58876 to your computer and use it in GitHub Desktop.
Run Javascript with Selenium. Easily.
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
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 |
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
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