Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

276
Views
How to open and control a new tab TARGET _BLANK by click puppeteer

there is a button that open a new tab (_blank) in browser, how do i reference this(like "await page2...") new tab and control it?

<button id="button" href="randomCode" target="_blank">BUTTON</button>

I tried use this in puppeteer:

await page1.waitForSelector('#button');
const link = await page1.$('#button');
const newPagePromise = new Promise(x => browser.once('targetcreated', target => x(target.page())));
await link.click({button: 'left'});            
const page2= await newPagePromise;   
await page2.bringToFront();    

But in this case, it only work to control sometimes (I don’t know why)

Note: The button link change with time, so it's necessary to click in the button/ can't close the first page.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If there is someone with the same error, I found the solution, get the href of button, and then, open a new tab with the href:

const hrefs1 = await page.evaluate(
  () => Array.from(
    document.querySelectorAll('a[SELECTOR]'),
    a => a.getAttribute('href')
  )
);

const pagina2 = await browser.newPage();
await pagina2.goto(''+hrefs1);

There is no error in this case.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!