0

I use Selenium with cucumber in Java and when trying to do that :

WebElement MyAccountLink = driver.findElement(By.className("btn-outlined-white_medium_block"));
MyAccountLink.click();

I got this error:

org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"class name","selector":"btn-outlined-white_medium_block"}

How can i solve it ? Thanks.

6
  • You have a space in the class name before _block. Commented Feb 7, 2018 at 11:27
  • Sorry i corrected it and now i have : org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"class name","selector":"btn-outlined-white_medium_block"} Commented Feb 7, 2018 at 11:29
  • Try to find with id or name Commented Feb 7, 2018 at 11:31
  • 1
    Add relevant html code Commented Feb 7, 2018 at 11:53
  • 1
    This error can come due to multiple reasons. The HTML will help us in giving the correct answer. Commented Feb 7, 2018 at 11:56

1 Answer 1

1

use 'XPath' or 'cssSelector' instead of 'className', because it doesn't matters which locator you are using. you need to find the element and do automation on that element.

WebElement MyAccountLink = driver.findElement(By.xpath("right click on element and copy xpath and paste it here"));
MyAccountLink.click();

Hope XPath will work in any case.

Sign up to request clarification or add additional context in comments.

1 Comment

@A.Java If my answer solved your query, then you can click on the green tick mark on the left side. thank you.

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.