Capybara gives you two different methods for executing Javascript:
page.evaluate_script("$('input').focus()")
page.execute_script("$('input').focus()")
While you can use both, the first line (with evaluate_script
) might freeze your browser window for 10 seconds.
The reason is that evaluate_script
will always return a result. The return value will be converted back to Ruby objects, which in case of complex objects (e.g. a jQuery collection) is very expensive.
Because of this we recommend to only use evaluate_script
when you require access to the result value.
Posted by Henning Koch to makandra dev (2012-11-08 16:04)