java.lang.Object
net.serenitybdd.screenplay.playwright.interactions.ExecuteJavaScript
All Implemented Interfaces:
net.serenitybdd.core.SkipNested, net.serenitybdd.screenplay.Performable

public class ExecuteJavaScript extends Object implements net.serenitybdd.screenplay.Performable
Execute JavaScript on the current page.

Playwright's evaluate method passes arguments directly to the expression. For multiple arguments, use an arrow function with array destructuring:

Sample usage:

     // No arguments
     actor.attemptsTo(
         ExecuteJavaScript.async("window.scrollTo(0, document.body.scrollHeight)")
     );

     // Single argument (available as 'arg')
     actor.attemptsTo(
         ExecuteJavaScript.async("arg => document.getElementById(arg).click()")
             .withArguments("myButton")
     );

     // Multiple arguments (use array destructuring)
     actor.attemptsTo(
         ExecuteJavaScript.async("([a, b]) => document.title = a + ' ' + b")
             .withArguments("Hello", "World")
     );
 
  • Method Details

    • async

      public static ExecuteJavaScript async(String script)
      Execute JavaScript asynchronously.
    • withArguments

      public ExecuteJavaScript withArguments(Object... args)
      Provide arguments to the script. Single argument is available directly, multiple arguments are passed as an array.
    • performAs

      public <T extends net.serenitybdd.screenplay.Actor> void performAs(T actor)
      Specified by:
      performAs in interface net.serenitybdd.screenplay.Performable