1

My code begins by signing me into PayPal, then signing into eBay and navigating to the pay fees page, then checking out with PayPal. The final "Continue" button I can't click/submit. I've tried by xpath, id and class. I even tried sending TAB 7x until the Continue button and then sending Enter but that didn't work.

I have found this discussion but I'm not sure how to make it work for me. PayPal Sandbox checkout 'continue button' - Unable to locate element: - C# WebDriver

Here's a screenshot of the PayPal code and page I'm trying to do. screenshot

    //Chrome WebDriver specific
    System.setProperty("webdriver.chrome.driver", "C:\\automation\\drivers\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.manage().window().maximize(); //maximise webpage
    WebDriverWait wait = new WebDriverWait(driver, 20);

    //navigate to Paypal
    driver.get("https://www.paypal.com/uk/signin");

    //wait 2.5s for the page to load
    try {
        Thread.sleep(2500);
    }
    catch (Exception e) {
        e.printStackTrace();
    }

    WebElement paypalEmail = driver.findElement(By.id("email"));
    paypalEmail.sendKeys("******");

    //wait 2.5s for the page to load
    try {
        Thread.sleep(2500);
    }
    catch (Exception e) {
        e.printStackTrace();
    }

    WebElement paypalSubmit = driver.findElement(By.id("btnNext"));
    paypalSubmit.click();

    String URL = ("https://www.paypal.com/uk/signin");
    driver.get(URL);
    WebElement form2 = driver.findElement(By.cssSelector(".main form"));
    WebElement username = form2.findElement(By.id("password"));
    username.sendKeys("******");

    WebElement paypalSubmit2 = driver.findElement(By.id("btnLogin"));
    paypalSubmit2.click();

    //navigate to Ebay
    driver.get("https://signin.ebay.co.uk/ws/eBayISAPI.dll?SignIn&ru=https%3A%2F%2Fwww.ebay.com%2F");

    // Enter user name , password and click on Signin button
    WebElement form = wait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("#mainCnt #SignInForm")));

    form.findElement(By.cssSelector("input[type=text][placeholder='Email or username']")).sendKeys("******");
    form.findElement(By.cssSelector("input[type=password]")).sendKeys("******");

    form.findElement(By.id("sgnBt")).click();

    driver.get("http://cgi3.ebay.co.uk/ws/eBayISAPI.dll?OneTimePayPalPayment");

    //WebElement Pay =
    driver.findElement(By.xpath("//input[@value='Pay']")).click();

    WebDriverWait wait2 = new WebDriverWait(driver, 15);
    wait2.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id=\"confirmButtonTop\"]")));
    driver.findElement(By.xpath("//*[contains(@id,'confirmButtonTop')]")).click();
}
}
Hamed Adefuwa
  • 43
  • 1
  • 8

3 Answers3

2

Based on your given screenshot one of following should work to click on continue button :

Method 1 :

  WebElement paypalSubmit = driver.findElement(By.xpath("//input[@data-test-id='continueButton']"));
  paypalSubmit.click();

Method 2:

By paypalButton=By.xpath("//input[@data-test-id='continueButton']"));
WebElement element=driver.findElement(paypalButton);    
JavascriptExecutor js = (JavascriptExecutor) driver;  
js.executeScript("arguments[0].scrollIntoView(true);",element);
js.executeScript("arguments[0].click();", element);

Try 2nd method if you feel your button require bit scroll to bottom to get clickable.

one more xpaths you can use for button if above don't work :

//input[@value='Continue' and @id='confirmButtonTop']
Helping Hands
  • 5,292
  • 9
  • 60
  • 127
  • Thanks for the speedy response, much appreciated. Somehow the 1st and 3rd option didn't work. It went to the Paypal screen and sat there. I'm intrigued by the second option to scroll down. However when I type "js.execute" the "js" comes up in red stating "Cannot resolve symbol 'js'". I'm using IntelliJ if that makes any difference. – Hamed Adefuwa Mar 22 '18 at 18:27
  • I managed to remove the error by adding JavascriptExecutor js = (JavascriptExecutor)driver; However, this still didn't click the continue button. – Hamed Adefuwa Mar 22 '18 at 18:48
  • No, unfortunately, I haven't been able to get it to work yet. – Hamed Adefuwa Mar 22 '18 at 18:59
2

In my experience, paypal likes to use iFrames. If that's true in your case, that means unless you tell webdriver to switch frame contexts, that paypal form will be unavailable to you regardless of your xpath/css selectors.

You can get a list of all available frames currently loaded with this code:

String[] handles = driver.getWindowHandles()

Your actual page will always be the 0th index in that returned array. If paypal is your only iFrame, then you can target the 1th index. Here's a possible solution to that:

String mainPageHandle = handles[0];
String paypalHandle = handles[1];

driver.switchTo().window(paypalHandle);
// Do paypal interactions

driver.switchTo().window(mainPageHandle);
// Back to the main page

There are definitely more robust ways to handle this, and if your page unfortunately has more than one iFrame, then you may need to do more to verify which handle is which, such as test the presence of an element you know is contained within. In general, the frames will load in the same order every time. As a golden path to this problem, this will get you in and out of that iFrame to perform work.

Julian
  • 1,665
  • 2
  • 15
  • 33
1

Sometimes the conventional click() doesn't work. In that case, try using the Javascript Executor Click as below.

Make sure you import this class

org.openqa.selenium.JavascriptExecutor

And use this instead of click();

JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", driver.findElement(By.xpath(“//input[@data-test-id='continueButton']”)));

Try this and let me know if this works for you.

S K
  • 308
  • 2
  • 6
  • 20