Skip to content

Instantly share code, notes, and snippets.

@junagao
Last active March 4, 2024 10:43
Show Gist options
  • Save junagao/2794d0d1ac9914e5d3613178e3f8775a to your computer and use it in GitHub Desktop.
Save junagao/2794d0d1ac9914e5d3613178e3f8775a to your computer and use it in GitHub Desktop.
Puppeteer

How to get text from an element:

const element = await page.$('.some-class');
const text = await page.evaluate(element => element.textContent, element);
// or
const text = await page.evaluate(element => element.innerText, element);
const text = await page.$eval('#some-id', el => el.textContent);

How to wait for an element to disappear or removed from DOM:

await page.waitForSelector('.some-class', {hidden: true});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment