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();
DebanjanB
  • 118,661
  • 30
  • 168
  • 217
redoptics
  • 55
  • 5

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();
    
DebanjanB
  • 118,661
  • 30
  • 168
  • 217
0

You can use icon on your button CSS:

.icon-chevron-right right

or xpath:

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

HedgeHog
  • 2,932
  • 2
  • 2
  • 15
Gaj Julije
  • 646
  • 4
  • 24