TestCafe .click不会在iFrame中触发onClick事件

Rob*_*b C 1 iframe automated-tests clicking e2e-testing testcafe

我正在尝试使付款系统自动化,其中“用PayPal付款”按钮位于iFrame中。我已经搜索了TestCafe的支持页面,但似乎无法解决问题。

TestCafe认为它已经单击了按钮,因此在下一步(输入电子邮件地址)时失败。

我正在使用什么:

const payPalFrame = Selector('#paypal-button iframe');
const payPalButton = Selector('[name="paypal"]')

async payWithPaypal () {
    await t
        .switchToIframe(payPalFrame)
        .click(payPalButton)
        .switchToMainWindow();
}
Run Code Online (Sandbox Code Playgroud)

我试图编写一个ClientFunction,但是对JS / Node来说还是比较新的东西,什么也没用。

hdo*_*val 5

也许您可以确保以这种方式使用该按钮:

await t
  .switchToIframe(payPalFrame)
  .expect(payPalButton.with({visibilityCheck: true}).exists)
  .ok({timeout: 30000})
  .hover(payPalButton)
  .click(payPalButton)
  .switchToMainWindow();
Run Code Online (Sandbox Code Playgroud)

如果这不起作用,则应尝试单击按钮父容器:

const payPalButton = Selector('[name="paypal"]').parent();
await t
  .switchToIframe(payPalFrame)
  .expect(payPalButton.with({visibilityCheck: true}).exists)
  .ok({timeout: 30000})
  .hover(payPalButton)
  .click(payPalButton)
  .switchToMainWindow();
Run Code Online (Sandbox Code Playgroud)

  • @RobC,在这种情况下,建议您设置一个公共存储库以展示此问题,然后在TestCafe上打开一个问题 (4认同)