1

I'm attempting to automate a payment system, where the "Pay with PayPal" button is within an iFrame. I've searched through TestCafe's support pages, and can't seem to resolve the issue.

TestCafe believes it has clicked on the button, and so fails at the next step (enter email address).

What I'm using:

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

async payWithPaypal () {
    await t
        .switchToIframe(payPalFrame)
        .click(payPalButton)
        .switchToMainWindow();
}

I tried to write a ClientFunction, but still relatively new to JS/Node and couldn't get anything to work.

Rob C
  • 662
  • 5
  • 15

2 Answers2

5

Maybe you could ensure that the button is available this way:

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

If this does not work, you should try to click on the button parent container:

const payPalButton = Selector('[name="paypal"]').parent();
await t
  .switchToIframe(payPalFrame)
  .expect(payPalButton.with({visibilityCheck: true}).exists)
  .ok({timeout: 30000})
  .hover(payPalButton)
  .click(payPalButton)
  .switchToMainWindow();
hdorgeval
  • 3,000
  • 8
  • 17
  • Neither of those have helped sadly... When in debug mode I'm also unable to click the button manually... so I'm not sure if this could actually be a "bug"... – Rob C Mar 22 '19 at 19:00
  • 4
    @RobC, in this case, I suggest you to setup a public repo where you can showcase this problem, and then open an issue on TestCafe – hdorgeval Mar 22 '19 at 21:48
  • Upon further investigation, it looks like the page didn't finish rendering properly prior to attempting the button click. So although your solution didn't resolve my issue, it did lead me down the path to discovering what the cause was. I'll accept your answer. – Rob C Apr 10 '19 at 18:38
0

There is a bug in testcafe that the iframes sometimes doesn't load their stylesheets therefore you may want to check if the tag which needs to be clicked in the iframe has the proper width, height and position.