GyaaniGuy

- self made 💻 😎

Automation with playwright - Part Last Miscellenous

When clicking a link that opens a new tab (target=“_blank”), use context.waitForEvent.


  // Start waiting for new page before the click
  const pagePromise = context.waitForEvent('page');

  // Perform click that opens new tab
  await page.locator('a[target="_blank"]').click();

  // Wait for and capture the new page
  const newPage = await pagePromise;
  await newPage.waitForLoadState();


dated April 2025