Last active
October 15, 2022 21:37
-
-
Save jecfish/419995d869060a9fb6bcd35e65176aba to your computer and use it in GitHub Desktop.
Puppeteer Text Selector
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
import puppeteer from 'puppeteer'; | |
(async () => { | |
const browser = await puppeteer.launch(); | |
const page = await browser.newPage(); | |
await page.goto('https://developer.chrome.com/blog/extend-recorder/'); | |
// Use unique text as selector | |
// It's not neccessary to specify full text in the selector | |
const textSelector = await page.waitForSelector('text/Chrome DevTools Recorder'); | |
// Get full text content | |
const fullTitle = await textSelector.evaluate(el => el.textContent); | |
console.log('Blog post title: %s', fullTitle); | |
// -> Blog post title: Customize and automate user flows beyond Chrome DevTools Recorder | |
// How about this one? Guess the result 😏 | |
const tryThisSelector = await page.$('text/YeenDev'); | |
console.log(await tryThisSelector.evaluate(el => el.innerHTML)); | |
await browser.close(); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment