Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

198
Views
Can't find any tags using NodeJS, puppeteer, and document.querySelector

I have a NodeJS Typescript project, and I am trying to get all the 'p' tags from a dynamically rendered website (not STATIC HTML but instead makes multiple requests to backend to get some data and render webpage). I am using typescript and have ["es6", "dom"] in my lib, and I have the following code (this is all my code in the project so far):

import puppeteer from 'puppeteer';

const getLinks = async () => {
    const browser = await puppeteer.launch();
    const [page] = await browser.pages();

    await page.goto('https://webscraper.io/test-sites', { waitUntil: 'networkidle0' });
    const links = await page.evaluate(() => document.querySelectorAll('p'));
    console.log(links);
    await browser.close();
}

However, I keep getting undefined when I print links. I assume this is because the program can't find any 'p' tags. Why is this?

Note: the url provided is just an example. I have tried across multiple different sites and I still get undefined.

Any help is appreciated! Thanks!

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Don't use page.evaluate to get elements, use waitForSelector/waitForXpath/$x/$$ instead (see Puppeteer doc to know the differences between them: https://devdocs.io/puppeteer/index#pageselector-1):

const links: ElementHandle[] = await mainPage.$$("p");
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!