Xupla
Xupla

Reputation: 203

Selenium with NUnit and .Net giving NoSuchElementExcpection

I am using selenium for automated testing. When the test runs on Selenium IDE it runs successfully then, when exporting it as a .Net web driver and run it with NUnit the NoSuchElementsException is being thrown. Do someone what is causing this exception please?

SeleniumTests.UserNotLogged.TheUserNotLoggedTest:

OpenQA.Selenium.NoSuchElementException : Unable to locate element: {"method":"link text","selector":""} //Exception from NUnit

[Test]
    public void TheUserNotLoggedTest()
    {
        driver.Navigate().GoToUrl(baseURL + "Index.aspx");
        driver.FindElement(By.Id("wrapper")).Click();
        driver.FindElement(By.LinkText("Home")).Click();
        driver.FindElement(By.LinkText("News")).Click(); //Exception thrown here
        driver.FindElement(By.LinkText("Events")).Click();
        driver.FindElement(By.LinkText("Contact Us")).Click();
        driver.FindElement(By.LinkText("Register")).Click();
    }

Thanks for your help

Upvotes: 1

Views: 1624

Answers (1)

Arran
Arran

Reputation: 25076

In these kind of cases, it's generally a timing issue. I take it these are navigation links? In which case, it could well be that Selenium is trying to find the News link well before the page has finished loading. Try adding in a WebDriverWait:

http://seleniumhq.org/docs/04_webdriver_advanced.html

If this still doesn't solve it, move to a different method of finding the links, such as a css selector or XPath - just to verify that you CAN find it using a different method (albeit not the best one).

Upvotes: 3

Related Questions