Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using Selenium 2.0 web driver. My script keeps failing whenever I try locating something in my page. It throws an exception whether I locate the element by LinkText or by XPath.


OpenQA.Selenium.NoSuchElementException : Unable to locate element: {"method":"link text","selector":"Products"}


OpenQA.Selenium.NoSuchElementException : Unable to locate element: {"method":"xpath","selector":"//div[@id='nav']/ul/li[0]/a"}
share|improve this question

XPath list indexes are one-based, not zero-based. Try li[1].

share|improve this answer
thanks.. that's good to know... +1 ... I was testing with this wait when I had the linkText, so I'll correct that (good catch) ==> driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10)); ... my actual issue seems to be related to this waiting – MacGyver Jan 17 '12 at 20:18

A few things to look at.

  1. Are you sure that the LinkText is correct? Are you missing spaces, non breaking spaces, etc that may appear in the html but you don't see as a user?
  2. Are you sure the xpath is correct?
  3. Is this a timing issue? Are you trying to find the elements before the page is finished loading or before those elements are loaded?
share|improve this answer
+1 for you my friend.. however I found the issue. Perhaps you can help me find a better alternative to my solution. It was related to the waiting. – MacGyver Jan 17 '12 at 20:20
Personally, I don't even like Selenium's wait functions, they seem too fragile and I have to be explicit in what I want to wait for. In my selenium wrapper classes I implemented polling/retry logic on every action, so I can navigate to a new page and immediately call a click method on an element I know won't appear for another 10 seconds and it will try and retry up to a specified amount of time and eventually either work or time out. This has avoided so many headaches for me. – Sam Woods Jan 18 '12 at 22:35
up vote 1 down vote accepted

Seems like I have to use this line of code before I invoke any click events. The "clickAndWait" conversion of the Selenium IDE to Webdriver doesn't seem to work properly. It converts everything to *.Click(). Adding the implicit wait after every click event and setting WAIT_TIME to 3 in my Constants class seems to do the trick.

share|improve this answer

Try either:

driver.find_element_by_xpath(u'//a[text()="Foo text"]')

or dedicated driver method:

driver.find_element_by_link_text("Foo text")

Add .click() if needed.

For troubleshooting, check this post at SO, as maybe your page isn't loaded yet, so you probably need to write a wait wrapper to wait for an element to appear.

share|improve this answer

This selenium webdriver tutorial explains how to click a link by its href:

share|improve this answer
it's ok to refer someone to another web page, but you should also try to answer the question without requiring someone to click on the link. – user246 Mar 21 at 17:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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