Last active
February 5, 2020 19:59
-
-
Save vsemozhetbyt/67c0d4951c79ee216d567a21d926bad2 to your computer and use it in GitHub Desktop.
page.evaluateHandle() example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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