How to use waitForSelector in Puppeteer to get all p tags on a page?

29 Replies, 2353 Views

Hey y’all,
I’m trying to figure out how to use waitForSelector Puppeteer get all p tags on a page. Like, I want to make sure the page is fully loaded before grabbing all the `<p>` elements.

I tried something like:
```javascript
await page.waitForSelector('p');
const paragraphs = await page.$$('p');
```
But idk if this is the *best* way or if I’m missing something.

Also, what if the page has dynamic content? Will waitForSelector Puppeteer get all p tags even if they load later? Or do I need to handle that differently?

Any tips or examples would be super helpful! Thanks in advance Smile

Messages In This Thread
How to use waitForSelector in Puppeteer to get all p tags on a page? - by - 12-02-2025, 02:36 AM



Users browsing this thread: 1 Guest(s)