0

I am trying to perform a simple checkout flow on my staging website, but I cant seem to find the element. I tried to use selenium IDE which works but when it comes to coding in java I keep getting stuck on secure checkout

this is the element button I want to click

<a class="checkout-anchor click-button display-flex vertical-align-center justify-center" href="javascript:void(0);" onclick="onCheckout()" data-stepid="cartstep04">
<img src="https://release.squareoffnow.com/public/assets/images/checkout/svg/secure.svg" class="secure-pic ls-is-cached lazyloaded" alt="">Secure Checkout</a>

This is the code i have written so far

package googleTestCases;

import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class simpleCartFlow {
    public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver","/Users/manavmehta/Desktop/squareoffSeleniumProjects/chromedriver");
        WebDriver driver=new ChromeDriver();
        driver.get("http://release.squareoffnow.com/");
        driver.manage().window().setSize(new Dimension(1440, 789));
        driver.findElement(By.linkText("Products")).click();
        driver.findElement(By.cssSelector(".store-buy-pro-button")).click();
        driver.findElement(By.cssSelector(".pro-twinpack-button")).click();
        driver.findElement(By.cssSelector(".whole-purchase-button")).click();
        driver.findElement(By.cssSelector(".productAvailability > .click-button")).click();
        driver.findElement(By.cssSelector(".giftpackSubmit")).click();
        System.out.println("button not clicked");
        driver.findElement(By.cssSelector(".checkout-anchor")).click();
        System.out.println("button clicked");


        driver.quit();
    }
}

instead of using a CSS selector I also tried to use linkText but it still didn't work

I keep getting this error enter image description here

1 Answers1

0

I suspect your issue is due to not waiting long enough for the element to appear. I ran the following successfully using the exact same selectors you had (although with Python instead of Java):

from seleniumbase import BaseCase

class MyTestClass(BaseCase):
    def test_base(self):
        self.open("https://release.squareoffnow.com/")
        self.click_link("Products")
        self.click(".store-buy-pro-button")
        self.click(".pro-twinpack-button")
        self.click(".whole-purchase-button")
        self.click(".productAvailability > .click-button")
        self.click(".giftpackSubmit")
        self.click(".checkout-anchor")

Full disclosure: This particular framework, SeleniumBase is one that I personally built, and it uses smart-waiting to make sure that elements have fully loaded before taking action. Java probably has something similar so that you can wait for the element to be clickable so that you don't have to sleep for an arbitrary amount of time between steps.

Michael Mintz
  • 9,007
  • 6
  • 31
  • 48
  • @ManavMehta As per advice above, see this answer which will provide the wait till clickable option for selenium java: https://stackoverflow.com/a/60485028/11543023 – djmonki May 26 '22 at 14:30
  • looking at what you said, I added an implicit wait of 10 seconds and it found the element. appreciate the help – Manav Mehta May 31 '22 at 10:26