mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
4ebf117116
* docs: a small batch of page TSdoc migration Co-authored-by: Changhao Han <changhaohan@chromium.org>
1.6 KiB
1.6 KiB
Home > puppeteer > Page > $$eval
Page.$$eval() method
This method runs Array.from(document.querySelectorAll(selector))
within the page and passes the result as the first argument to the pageFunction
.
Signature:
$$eval<ReturnType extends any>(selector: string, pageFunction: EvaluateFn | string, ...args: SerializableOrJSHandle[]): Promise<ReturnType>;
Parameters
Parameter | Type | Description |
---|---|---|
selector | string | the selector to query for |
pageFunction | EvaluateFn | string | the function to be evaluated in the page context. Will be passed the result of Array.from(document.querySelectorAll(selector)) as its first argument. |
args | SerializableOrJSHandle[] | any additional arguments to pass through to pageFunction . |
Returns:
Promise<ReturnType>
The result of calling pageFunction
.
Remarks
If pageFunction
returns a promise $$eval
will wait for the promise to resolve and then return its value.
Example 1
const divCount = await page.$$eval('div', divs => divs.length);
Example 2
const options = await page.$$eval(
'div > span.options', options => options.map(option => option.textContent));