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();
2
  • Please post the error stack? Commented Dec 18, 2020 at 12:20
  • Another srange thing no errors Commented Dec 18, 2020 at 13:17

2 Answers 2

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();
    
Sign up to request clarification or add additional context in comments.

Comments

0

You can use icon on your button CSS:

.icon-chevron-right right

or xpath:

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

1 Comment

Just tried this and its not working either, so strange

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.