Class ExecuteJavaScript
java.lang.Object
net.serenitybdd.screenplay.playwright.interactions.ExecuteJavaScript
- All Implemented Interfaces:
net.serenitybdd.core.SkipNested,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 Summary
Modifier and TypeMethodDescriptionstatic ExecuteJavaScriptExecute JavaScript asynchronously.<T extends net.serenitybdd.screenplay.Actor>
voidperformAs(T actor) withArguments(Object... args) Provide arguments to the script.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.serenitybdd.screenplay.Performable
then
-
Method Details
-
async
Execute JavaScript asynchronously. -
withArguments
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:
performAsin interfacenet.serenitybdd.screenplay.Performable
-