Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
0
rated 0 times [  3] [ 3]  / answers: 1 / hits: 18891  / 5 Years ago, tue, april 16, 2019, 12:00:00

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?


More From » node.js

 Answers
55

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();
})
}

[#52234] Wednesday, April 10, 2019, 5 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
dillionsalvadorg

Total Points: 288
Total Questions: 103
Total Answers: 75

Location: South Korea
Member since Sat, Oct 2, 2021
3 Years ago
;