Method: Capybara::Node::Element#evaluate_async_script

Defined in:
lib/capybara/node/element.rb

#evaluate_async_script(script, *args) ⇒ Object

Evaluate the given JavaScript in the context of the element and obtain the result from a callback function which will be passed as the last argument to the script. this in the script will refer to the element this is called on.

Parameters:

  • script (String)

    A string of JavaScript to evaluate

Returns:

  • (Object)

    The result of the evaluated JavaScript (may be driver specific)



529
530
531
532
533
534
535
# File 'lib/capybara/node/element.rb', line 529

def evaluate_async_script(script, *args)
  session.evaluate_async_script(<<~JS, self, *args)
    (function (){
      #{script}
    }).apply(arguments[0], Array.prototype.slice.call(arguments,1));
  JS
end