Why I got document is not defined error in puppeteer?
13,977
Solution 1
I think document would only be available within page.evaluate
(according to puppeteer documentation )
Try:
async function gallery(page) {
await page.waitFor(3000);
await page.evaluate(() => {
document.querySelector('div.image').click();
})
}
Solution 2
you are calling invalid element , you can check this document
await page.evaluate(() => {
document.querySelector('div.image').click();
});
Author by
Con Troll
Updated on June 20, 2022Comments
-
Con Troll almost 2 years
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.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?
-
Con Troll about 5 yearsI still got document is not defined with
div.image
too. -
Muhammad Ali about 5 yearsyou can check this one
-
Vipin Verma almost 3 yearsHow do you use it while debugging in console? It seems to be working fine, but when in debug mode with a breakout within page.eval it gives doc is not defined error