[英]puppeteer page.evaluate loop wait between click
I'm trying to make 1 sec wait between clic inside my loop, it not working, have you an idea how can i make that?我试图在循环内的 clic 之间等待 1 秒,但它不起作用,你知道我该怎么做吗? Thanks
谢谢
await page.goto("https://mywebsite.local");
page.evaluate(()=>{
let elements = document.querySelectorAll("a.special.video");//25-30 element
for (let element of elements){
setTimeout(() => {
element.click();
}, 1000);
}
});
i must wait between click because on every click i'm waiting ajax refresh content我必须在点击之间等待,因为每次点击我都在等待 ajax 刷新内容
You can multiply the index value to get the 1 second separation before the clicks:您可以将索引值相乘以获得点击前的 1 秒间隔:
page.evaluate(()=>{
let elements = document.querySelectorAll("a.special.video");//25-30 element
elements.forEach((element, index) => {
setTimeout(() => {
element.click();
}, index * 1000);
})
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.