puppeteer/new-docs/puppeteer.page.__eval.md
Changhao Han 4ebf117116
docs: migrating Page.ts to TSDoc (#6152)
* docs: a small batch of page TSdoc migration

Co-authored-by: Changhao Han <changhaohan@chromium.org>
2020-07-03 13:12:59 +01:00

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));