title: Collect elements by class name and then click each one - Puppeteer
body: <p>Using Puppeteer, I would like to get all the elements on a page with a particular class name and then loop through and click each one.</p>
  
  <p>Using jQuery, I can achieve this with:</p>
  
  <pre><code>var elements = $("a.showGoals").toArray();
  
  for (i = 0; i &lt; elements.length; i++) {
    $(elements[i]).click();
  }
  </code></pre>
  
  <p>How would I achieve this using Puppeteer?</p>
  
  <h2>Update</h2>
  
  <p>Tried out Chridam's answer below, but I couldn't get it to work (though the answer was helpful, so thanks due there), so I tried the following and this works:</p>
  
  <pre><code> await page.evaluate(() =&gt; {
     let elements = $('a.showGoals').toArray();
     for (i = 0; i &lt; elements.length; i++) {
       $(elements[i]).click();
     }
  });
  </code></pre>