简体   繁体   中英

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? 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

You can multiply the index value to get the 1 second separation before the clicks:

page.evaluate(()=>{
    let elements = document.querySelectorAll("a.special.video");//25-30 element
    elements.forEach((element, index) => {
        setTimeout(() => {
            element.click();
        }, index * 1000);  
    })
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM