title: Puppeteer : Timeout or sleep or wait inside Page.Evaluate()
body: <p>I need a way to add some delay between clicking elements inside a page.evaluate function</p>
  
  <p>below is what ive tried and it does not work</p>
  
  <pre><code>const result = await page.evaluate(async () =&gt; {
          let variants = document.querySelectorAll(".item-sku-image a");
  
  
          variants.forEach(async variant =&gt; {   
             await new Promise(function(resolve) { 
             setTimeout(resolve, 1000)
             });         
              await variant.click()
          });
          return data
      });
  </code></pre>
  
  <p>Update: </p>
  
  <p>the for loop below works fine for one element
  when i try to use another for loop inside it - it goes crazy</p>
  
  <pre><code>const variants = [...document.querySelectorAll(".item-sku-image a")]; // Turn nodelist into an array
  const sizes = [...document.querySelectorAll(".item-sku-size a")]; // Turn nodelist into an array
  
  for (let variant of variants){
    // wait one second
    await new Promise(function(resolve) {setTimeout(resolve, 1000)});
    await variant.click()
    for (let size of sizes){
     // wait one second
     await new Promise(function(resolve) {setTimeout(resolve, 1000)});
     await size.click()
   }
  }
  </code></pre>