Method: Capybara::Node::Element#evaluate_script
- Defined in:
- lib/capybara/node/element.rb
#evaluate_script(script, *args) ⇒ Object
Evaluate the given JS in the context of the element and return the result. Be careful when using this with
scripts that return complex objects, such as jQuery statements. #execute_script might
be a better alternative. this in the script will refer to the element this is called on.
512 513 514 515 516 517 518 |
# File 'lib/capybara/node/element.rb', line 512 def evaluate_script(script, *args) session.evaluate_script(<<~JS, self, *args) (function(){ return #{script.strip} }).apply(arguments[0], Array.prototype.slice.call(arguments,1)); JS end |