I want to click on Administration panel. The <span> contains a class attribute and inner text.

I get an error saying "unable to locate element". What am I doing wrong?


 <div class="item-inner">
      <span class="title"> Administration </span>
      <i class="icon-arrow"></i>

C# code

  var admi = driver.FindElement(By.XPath("//span[contains(@class,'title')]  [contains(text(),'Administration')]"));

  • var admi = driver.FindElement(By.XPath("//div[contains(@class,'title')] [contains(text(),'Administration')]")); Try this – sameer joshi Nov 18 '15 at 12:22

Try to avoid the use of contains as your method of finding an element. This will mainly cause you issues later down the line when other elements unintentionally match

I would suggest you use something more like;


This example still isn't ideal, and ideally you should ask your developers to add in a unique ID for you to utilize.

| improve this answer | |

Use following Xpath


Also make sure variable in which you are saving the element is of WebElement type.

| improve this answer | |

var admi = driver.FindElement(By.XPath("//span[contains(@class,'title') and contains(text(),'Administration')]"));

You were almost there.

| improve this answer | |

If you are using Pandas you can search by:


# create a new Firefox session
driver = webdriver.Firefox()
result = driver.find_elements_by_class_name('screen-reader-text')
| improve this answer | |

If the span element is the only element on the page with the ClassName "title", you could just get the element by ClassName:

IWebElement admin = driver.FindElement(By.ClassName("title"));

If the span element is not the only element with the ClassName "title", but is the only element with that ClassName under its parent, you can get the parent element then the span element:

IWebElment admin = driver.FindElement(By.ClassName("item-inner")).FindElement(By.ClassName("title"));

Otherwise, I would follow the advise of others using the XPath. Usually I try to use other methods of finding elements because XPath can be slow or unreliable.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.