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

标签 javascript jestjs e2e-testing webautomation playwright

我正在尝试访问新的弹出窗口以在 playwright 中进行 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)

关于javascript - 我如何切换到新的弹出窗口,例如在剧作家中点击“用谷歌注册”时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67059276/

相关文章:

javascript - 尝试仅在源为 jpg 时加载函数

javascript - NVD3怎么了?

react-native - 在 React Native 中使用 Jest 测试在对象上调用的函数

javascript - 如何在 NX 项目中使用 es6 将 jest 与 node_modules 一起使用

selenium - 在 Excel/CSV 与 DB 中存储测试数据

angular - 如何修复 TypeError : cy. document(...).toMatchSnapshot is not a function?

javascript - 文字伴侣 $TM_SELECTED_TEXT

javascript - 在遍历数组时从数组中切片元素的 typescript 方法

javascript - 可能是我的一个简单的 Jest/ react 错误

testing - Windows Agent 上的 Testcafe 测试 IE