[英]Why I got document is not defined error in puppeteer?
我想模擬在圖庫( <div class="image">
)上的單擊,但是當我嘗試運行此代碼時,出現文檔未定義錯誤。
async function gallery(page) {
await page.waitFor(3000);
await page.click(document.querySelector('.div image'));
}
這是什么問題 我該如何正確地使用puppeteer的document.querySelector?
您正在調用無效元素,可以檢查此文檔
await page.evaluate(() => {
document.querySelector('div.image').click();
});
我認為文檔只能在page.evaluate
(根據page.evaluate
文檔 )
嘗試:
async function gallery(page) {
await page.waitFor(3000);
await page.evaluate(() => {
document.querySelector('div.image').click();
})
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.