我怎样才能切换到新的弹出窗口 windows 例如当点击在 playwright 中使用 google 注册时

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

我正在尝试访问 windows 的新弹出窗口 google 注册剧作家,但无法做到。

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

您应该等待弹出窗口然后对其进行操作:

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)