admin管理员组文章数量:1429130
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
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
- Possible duplicate of Accessing the await-ed value inline (JS)? – Heretic Monkey Commented Jun 5, 2018 at 16:19
2 Answers
Reset to default 5$$
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.
本文标签: javascriptPuppeteerpage(3939)length returns undefinedStack Overflow
版权声明:本文标题:javascript - Puppeteer - page.$$('').length returns undefined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745467182a2659584.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论