0

I am using selenium for my testing a retail website . Once I reached the Checkout page , I am selecting the option as Paypal Where a sandbox url is opening.

https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-07L974777B231831F#/checkout/login

I am able to enter the username and password , clicked on Login button.

After that I am redirected to "Agree & Continue " Page . Where I could not perform any action.

I could see clearly the button properties as below

enter image description here

I have tried the below code, but could not perform any action.

WebElement AgreeandContinue= driver.findElement(By.tagName("input"));
AgreeandContinue.click();
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

4 Answers4

0

You might have many input elements in the same page. What about trying to select by class or id?

WebElement AgreeandContinue= driver.findElement(By.ByClassName('btn'));

or

WebElement AgreeandContinue= driver.findElement(By.ByClassName('continueButton'));

then using submit() instead of click() as the element is a 'submit' type`

FYI : https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/WebElement.html

Yohannes Gebremariam
  • 2,225
  • 3
  • 17
  • 23
0

Looks like the button has an id defined, so that would be the best locator to use: driver.findElement(By.id("confirmButtonTop));

If that doesn't work, then you might have to add some waits for the button to be clickable.

And if that still doesn't work, then it's possible, as it is with many commercial tools, that the button is actually inside a different iframe. Look further up in the html to confirm if this is the case (it'll have a iframe tag). If that's the case, then you'll have to first switch to the iframe before clicking the button: driver.switchTo().frame(...) . How to identify and switch to the frame in selenium webdriver when frame does not have id

HaC
  • 902
  • 12
  • 24
0

If we look at the HTML you have provided the WebElement with value Agree & Continue is within an <input> tag. So we have to construct a unique css or xpath to identify the WebElement as follows:

  1. cssSelector :

    WebElement AgreeandContinue= driver.findElement(By.cssSelector("input#confirmButtonTop"));
    

OR

  1. xpath :

    WebElement AgreeandContinue= driver.findElement(By.xpath("//input[@id='confirmButtonTop']"));
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

Try with ID, but if it is not you can try with other locators , I suggest you have to use xpaths:

driver.findElement(By.xpath("//input[contains(@id,'confirmButtonTop')]")).click();

or

driver.findElement(By.xpath("//*[contains(@id,'confirmButtonTop')]")).click();

also I will suggest that you can use wait until element to be clickable or visible

WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[contains(@id,'confirmButtonTop')]")));
driver.findElement(By.xpath("//input[contains(@id,'confirmButtonTop')]")).click();

or

WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[contains(@id,'confirmButtonTop')]")));
driver.findElement(By.xpath("//*[contains(@id,'confirmButtonTop')]")).click();
iamsankalp89
  • 4,607
  • 2
  • 15
  • 36