1

I am currently working on a project I can select all elements barr one, and it getting really frustrating the code is as follows

<a class="btn btn-default button button-medium" href="http://automationpractice.com/index.php?controller=order" title="Proceed to checkout" rel="nofollow">
                        <span>
                            Proceed to checkout<i class="icon-chevron-right right"></i>
                        </span>
                    </a>

I have tried xpath, css, linktext, title and other methods but no luck, any help would be really appreaced

example of xpath I have used

driver.findElement(By.xpath("/html//div[@id='layer_cart']//a[@title='Proceed to checkout']/span")).click();

example of css I have used

driver.findElement(By.cssSelector("a[title='Proceed to checkout'] > span")).click();
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
redoptics
  • 65
  • 6

2 Answers2

2

To click() on the element you can use either of the following Locator Strategies:

  • cssSelector:

    driver.findElement(By.cssSelector("a.btn.btn-default.button.button-medium[title='Proceed to checkout'] > span")).click();
    
  • xpath:

    driver.findElement(By.xpath("//a[@class='btn btn-default button button-medium' and @title='Proceed to checkout']/span")).click();
    

Ideally to click() on the element you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

  • cssSelector:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.btn.btn-default.button.button-medium[title='Proceed to checkout'] > span"))).click();
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@class='btn btn-default button button-medium' and @title='Proceed to checkout']/span"))).click();
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

You can use icon on your button CSS:

.icon-chevron-right right

or xpath:

//i[@class='icon-chevron-right right']

HedgeHog
  • 22,146
  • 4
  • 14
  • 36
Gaj Julije
  • 1,538
  • 15
  • 32