Skip to content Skip to sidebar Skip to footer

Puppeteer - Page.$$('').length Returns Undefined

I was having errors with my code, so i tried to log the value in the erroneous code. So i did: const read = await page.$$('.Ns6lhs9 _gfh3').length; Then i console.log(read); For s

Solution 1:

$$ returns a promise of an element, while length is not a promise, it's actual value.

It should be:

const read = (await page.$$('.Ns6lhs9._gfh3')).length;

Solution 2:

I've had a similar issue with getting 0 when counting elements using CSS selector. I tried xpath selector instead and for some reason it did work.

Post a Comment for "Puppeteer - Page.$$('').length Returns Undefined"