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 some reason i get undefined
although there are elements with class name 'Ns6lhs9 _gfh3'
in the HTML
$$
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;
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.