Skip to content

Instantly share code, notes, and snippets.

@vsemozhetbyt
Last active February 5, 2020 19:59
Show Gist options
  • Save vsemozhetbyt/67c0d4951c79ee216d567a21d926bad2 to your computer and use it in GitHub Desktop.
Save vsemozhetbyt/67c0d4951c79ee216d567a21d926bad2 to your computer and use it in GitHub Desktop.
page.evaluateHandle() example
'use strict';
const puppeteer = require('puppeteer');
(async function main() {
try {
const browser = await puppeteer.launch();
const [page] = await browser.pages();
await page.goto('https://example.org/');
const allElements = await page.evaluateHandle(
() => [...document.querySelectorAll('*')]
);
const numberOfElements = await page.evaluate(
elements => elements.length, allElements
);
console.log(numberOfElements);
await browser.close();
} catch (err) {
console.error(err);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment