Skip to main content
Locator evaluation methods for the Playwright driver.

evaluate

Evaluates a function in the browser context with the element as first argument.
Returns the value of the evaluated function. The function receives the DOM element as first argument.
Upstream docs
pageFunction
string | ((element: Element, arg: Arg) => R | Promise<R>)
required
Function to evaluate in browser context
arg
Arg
Argument to pass to function
options
PlaywrightEvaluateOptions
result
R
Return value
await locator.evaluate(/* string | ((element: Element, arg: Arg) => R | Promise<R>) */);

evaluateAll

Evaluates a function with all matching elements as first argument.
Does not wait for elements - returns empty array if none match.
Upstream docs
pageFunction
string | ((elements: Element[], arg: Arg) => R | Promise<R>)
required
Function to evaluate in browser context
arg
Arg
Argument to pass to function
result
R
Return value
await locator.evaluateAll(/* string | ((elements: Element[], arg: Arg) => R | Promise<R>) */);

evaluateHandle

Returns a JSHandle with the result of the evaluation.
Use when you need to retain a reference to a JavaScript object in the page. Note: JSHandle is not fully supported in the remote SDK.
Upstream docs
pageFunction
string | ((element: Element, arg: Arg) => R | Promise<R>)
required
Function to evaluate in browser context
arg
Arg
Argument to pass to function
result
unknown
Return value
await locator.evaluateHandle(/* string | ((element: Element, arg: Arg) => R | Promise<R>) */);