2

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

1 Answers1

0

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);  
    })
});
Rashomon
  • 5,962
  • 4
  • 29
  • 67