Home > Enterprise >  Get popup URL after a new request from javascript on playwright
Get popup URL after a new request from javascript on playwright

Time:10-15

I have a button on a page that opens a popup (new tab). I can get this popup with a listener:

page.on('popup', async popup => {
       console.log('popup => '   await popup.url());
    })

The problem is that the website opens it with an "about:blank" link, and later loads an URL.

I tried to wait a few seconds before get the url but it keeps showing a blank string.

page.on('popup', async popup => {
       await page.waitForTimeout(10000);
       console.log('popup => '   await popup.url());
    })

The main page after opens the popup, changes it URL. So im not able, yet, to get this URL sent to the popup.

Any idea? Thanks!

CodePudding user response:

try to set the url on a const before console.logging

page.on('popup', async popup => {
     await page.waitForTimeout(10000);
     const url = await popup.url()
     console.log('popup => '   url);
})

CodePudding user response:

You can wait for navigation of the popup before printing out its url:

page.on('popup', async popup => {
  await popup.waitForNavigation();
  console.log('popup => '   await popup.url());
})
  • Related