user1579414
user1579414

Reputation: 27

how to get a div span class element

i am trying to display the number 1 in my console, apparently it did not work, any advise please

This is my code apparently it didn't work.

String error1 = driver.findElement(By.xpath("//div[@class='label label-error']/span[@class='sidebar-label']")).getText();

label tag

the console error output

  org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//div[@class='label label-error']/span[@class='sidebar-label']"}

Upvotes: 1

Views: 459

Answers (1)

Udhav Sarvaiya
Udhav Sarvaiya

Reputation: 10061

Your Xpath is Wrong, Use one of these:

  1. //div[@class="sidebar-label"]/span
  2. //div[@class="sidebar-label"]/span[@class="label label-error"]
  3. //*[@class="label label-error"]

Upvotes: 1

Related Questions