Puppeteer - page. $$('')。length返回undefined [英] Puppeteer - page.$$('').length returns undefined
本文介绍了Puppeteer - page. $$('')。length返回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;
然后我 console.log(读取);
出于某种原因,我得到 undefined
尽管有类名为的元素'Ns6lhs9 HTML中的_gfh3'
For some reason i get undefined
although there are elements with class name 'Ns6lhs9 _gfh3'
in the HTML
推荐答案
$$
返回元素的承诺,而 length
不是承诺,它是实际值。
$$
returns a promise of an element, while length
is not a promise, it's actual value.
它应该be:
const read = (await page.$$('.Ns6lhs9 _gfh3')).length;
这篇关于Puppeteer - page. $$('')。length返回undefined的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文