Search code examples
javascriptjestjse2e-testingwebautomationplaywright

How can I Switch to new Popup windows for e.g when clicking on sign up with google in playwright


i'm trying to access new popup windows for google sign up in playwright and couldn't do it.

await page.waitForSelector(signUpWithGoogle, { state: 'visible' })
await page.focus(signUpWithGoogle)
await page.click(signUpWithGoogle)
await page.fill('//input[@type="email"]', email)

Solution

  • You should wait for the popup and then action on it:

    await page.waitForSelector(signUpWithGoogle, { state: 'visible' })
    await page.focus(signUpWithGoogle)
    const [popup] = await Promise.all([
      page.waitForEvent('popup'),
      page.click(signUpWithGoogle),
    ]);
    
    await popup.fill('//input[@type="email"]', email)