title: Puppeteer: How to click element so it opens in new tab?
body: <p>I have got a list of 25 elements that are clickable. I need to open each one of them in a new tab, scrape the new page opened in a new tab, then close it. Then go to the next element and do the same for each element in the list.</p>
  <p>however, I am having problems opening the links in a new tab by clicking on them. I managed to open then with <code>page.goto('link&quot;)</code> but I want to make it more humanized and instead of pasting the link into the new tab I want to be opened by clicking.</p>
  <pre><code>let accountsClickElements = await page.$$eval(&quot;.result-lockup__name a&quot;, el =&gt; el.map(x =&gt; x.getAttribute(&quot;id&quot;)));
                                                                                          
   for (let i = 0; i&lt;25; i++) {
       await autoScroll(page);
       await page.waitFor(3000);
       let id = companies[i];
       await page.focus(&quot;#&quot;+accountsClickElements[0]);
       accountsClickElements = await page.$$eval(&quot;.result-lockup__name a&quot;, el =&gt; el.map(x =&gt; x.getAttribute(&quot;id&quot;)));
       await page.waitFor(3000);
       await page.focus(&quot;#&quot;+accountsClickElements[i]);                             
       await page.click(&quot;#&quot;+accountsClickElements[i]);
       await page.waitFor(2000);
       console.log(&quot;#&quot;+companies[i].linid);
       await page.goBack(); 
    }                              `
  </code></pre>
  <p>This is a code that opens the links in the same tab, but after a while, it doesn't take all 25 elements and since id is changing every time I open the page I get an error.</p>
  <p>I have changed the code like this so instead of clicking of the element, it is clicking on the href attribute. the target _blank attribute is there, but it still opening on the same tab. Can you point why?</p>
  <pre><code>await page.$$eval('.result-lockup__name a', el =&gt; el.map(x =&gt; x.setAttribute(&quot;target&quot;, &quot;_blank&quot;)));
  let accountsClickElements = await page.$$eval(&quot;.result-lockup__name a&quot;, el =&gt; el.map(x =&gt; x.getAttribute(&quot;href&quot;)));                                                                                                                  
  for (let i = 0; i&lt;25; i++) {
     await page.waitFor(2000);
     await autoScroll(page);
     await page.waitFor(2000);    
     await page.click('a[href=&quot;'+accountsClickElements[i]+'&quot;]');
  }
  </code></pre>