[英]Why I got document is not defined error in puppeteer?
I'd like to simulate a click on a gallery ( <div class="image">
) but when I try to run this code, I got document not defined error. 我想模拟在图库(
<div class="image">
)上的单击,但是当我尝试运行此代码时,出现文档未定义错误。
async function gallery(page) {
await page.waitFor(3000);
await page.click(document.querySelector('.div image'));
}
What's the problem here? 这是什么问题 How can I use document.querySelector correctly with puppeteer?
我该如何正确地使用puppeteer的document.querySelector?
I think document would only be available within page.evaluate
(according to puppeteer documentation ) 我认为文档只能在
page.evaluate
(根据page.evaluate
文档 )
Try: 尝试:
async function gallery(page) {
await page.waitFor(3000);
await page.evaluate(() => {
document.querySelector('div.image').click();
})
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.