Quantcast
Channel: Active questions tagged paypal - Stack Overflow
Viewing all articles
Browse latest Browse all 516

PayPal Advanced Checkout Web Automation Fails Sometimes in Selenium Java

$
0
0

I am automating the checkout process on a NopCommerce site using PayPal Advanced as the payment method. Most of the time, the automation works, but sometimes it fails to complete the payment.

When the payment works, the PayPal form looks like this:Successful paypal payment form

When it fails, the form looks like this:Failed paypal payment form

The main difference is how the card number is shown, with spaces between every four digits when it works.

At first, I used the sendKeys method in my selenium code:

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(60));    wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[@title='paypal_card_number_field']")));WebElement cardNumberInput = wait.until(ExpectedConditions.elementToBeClickable(By.name("number")));cardNumberInput.click();cardNumberInput.clear();cardNumberInput.sendKeys(cardNumber);driver.switchTo().defaultContent();

I thought sending the whole card number at once might be the problem, so I changed it to send one number at a time:

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(60));    wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[@title='paypal_card_number_field']")));WebElement cardNumberInput = wait.until(ExpectedConditions.elementToBeClickable(By.name("number")));cardNumberInput.click();cardNumberInput.clear();Actions actions = new Actions(driver); for (char c : cardNumber.toCharArray()){    actions.sendKeys(String.valueOf(c)).pause(500).perform(); }driver.switchTo().defaultContent();

Even with this change, the problem still happens sometimes. I tried adding waits before and after filling the card number, but the issue still comes up. The failure is random – sometimes it works, sometimes it doesn't.

What could be causing this issue, and how can I make the PayPal Advanced checkout more reliable in my automation?


Viewing all articles
Browse latest Browse all 516

Trending Articles