Page.$eval() method
This method runs document.querySelector
within the page and passes the result as the first argument to the pageFunction
.
Signature:
class Page {
$eval<
Selector extends string,
Params extends unknown[],
Func extends EvaluateFuncWith<NodeFor<Selector>, Params> = EvaluateFuncWith<
NodeFor<Selector>,
Params
>,
>(
selector: Selector,
pageFunction: Func | string,
...args: Params
): Promise<Awaited<ReturnType<Func>>>;
}
Parameters
Parameter | Type | Description |
---|---|---|
selector | Selector | the selector to query for |
pageFunction | Func | string | the function to be evaluated in the page context. Will be passed the result of document.querySelector(selector) as its first argument. |
args | Params | any additional arguments to pass through to pageFunction . |
Returns:
Promise<Awaited<ReturnType<Func>>>
The result of calling pageFunction
. If it returns an element it is wrapped in an ElementHandle, else the raw value itself is returned.