$$eval<T> method
This method runs document.querySelectorAll
within the element and passes
it as the first argument to pageFunction
. If there's no element matching
selector
, the method throws an error.
If pageFunction
returns a Promise
, then frame.$$eval
would wait for
the promise to resolve and return its value.
Examples:
<div class="feed">
<div class="tweet">Hello!</div>
<div class="tweet">Hi!</div>
</div>
var feedHandle = await page.$('.feed');
expect(
await feedHandle.$$eval('.tweet', 'nodes => nodes.map(n => n.innerText)'),
equals(['Hello!', 'Hi!']));
Parameters:
- A
selector
to query page for pageFunction
: Function to be evaluated in browser contextargs
: Arguments to pass topageFunction
Returns: Future which resolves to the return value of pageFunction
Implementation
Future<T?> $$eval<T>(String selector, @Language('js') String pageFunction,
{List<dynamic>? args}) async {
var arrayHandle = await evaluateHandle(
//language=js
'function _(element, selector) {return Array.from(element.querySelectorAll(selector));}',
args: [selector]);
var result = await arrayHandle.evaluate<T>(pageFunction, args: args);
await arrayHandle.dispose();
return result;
}