我如何切换到新的弹出窗口,例如在剧作家中点击“用谷歌注册”时

Arz*_*war 2 javascript webautomation jestjs e2e-testing playwright

我正在尝试访问谷歌在剧作家中注册的新弹出窗口,但无法做到这一点。

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

har*_*ded 5

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

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)
Run Code Online (Sandbox Code Playgroud)