0

I am running a selenium test using the grid mode. Whenever i am not able to find an element in the page, I am getting the following exception

"The HTTP request to the remote WebDriver server for URL http://localhost:4444/wd/hub/session/5fe58b67-491c-4b72-9a3a-a6dc790cc29d/element timed out after 60 seconds."

I was expecting an exception which is like NoSuch Element found. But I am getting a timeout. Any pointers on this would be much helpful

The code is below

try
{
    switch (findBy.ToLower())
    {
        case "classname":
            webElement = driver.FindElement(By.ClassName(findByValue));
            break;
        case "cssselector":
            webElement = driver.FindElement(By.CssSelector(findByValue));
            break;
        case "id":
            webElement = driver.FindElement(By.Id(findByValue));
            break;
        case "linktext":
            webElement = driver.FindElement(By.LinkText(findByValue));
            break;
        case "name":
            webElement = driver.FindElement(By.Name(findByValue));
            break;
        case "partiallinktext":
            webElement = driver.FindElement(By.PartialLinkText(findByValue));
            break;
        case "tagname":
            webElement = driver.FindElement(By.TagName(findByValue));
            break;
        case "xpath":
            webElement = driver.FindElement(By.XPath(findByValue));
            break;
    }
}
catch (Exception e)
{
    return null;
}

Many Thanks

Jason Boyd
  • 6,839
  • 4
  • 29
  • 47
Timothy Rajan
  • 1,947
  • 8
  • 38
  • 62
  • Timeout exception occurs when you are using explicit wait, and if element wasn't found even after waiting for the given time limit then timeout exception is thrown. – Pankaj Kumar Katiyar Mar 03 '16 at 05:34

1 Answers1

0

Pankaj Katiyar is correct that the timeout occurs because you are using an explicit wait. Selenium comes with an implicit wait as well, which says wait however long in seconds, if the element still doesn't show up, move on.

You could also try using wait until expected conditions and add them to all of your switch case statements.

Morgan G
  • 3,089
  • 4
  • 18
  • 26