Arzanish Sarwar
Arzanish Sarwar

Reputation: 135

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)

Upvotes: 3

Views: 2938

Answers (1)

hardkoded
hardkoded

Reputation: 21695

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)

Upvotes: 6

Related Questions