12

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?

1 Answer 1

18

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.