Reputation: 6029
It appears that Selenium has a feature called JavascriptExecutor
which makes it possible to execute JavaScript directly on the page. However it appears that there is no such thing available to my Cucumber/Capybara tests. How can I execute arbitrary JavaScript from my Cucumber tests?
Upvotes: 13
Views: 14945
Reputation: 339
Capybara has two methods to execute javascript #execute_script and #evaluate_script. Both can be found at: http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Selenium/Driver
However, do note that the readme has this statement about the above methods:
For simple expressions, you can return the result of the script. Note that this may break with more complicated expressions:
See http://rubydoc.info/github/jnicklas/capybara/master/file/README.md.
Upvotes: 19