Sometimes when I call the Selenium FindElements(By), it throws an exception and my driver stops to work. The parameter \"BY\" maybe can be the problem: when I use a different by
I found the problem. I'm using a method in all my test suit to wait the loading message dismiss. But it try using jquery and not all pages in my application use it.
So, selenium give up try execute jquery after 60 seconds and returns a timeout error, but this error does not broken the Selenium driver, only the FindElements then it returns a empty list. And when it try to return the empty list, all the drive broke.
The original method:
public void WaitLoadingMessage(int timeout)
{
while (timeout > 0)
{
try
{
var loadingIsVisible = _js.ExecuteScript("return $('#loading-geral').is(':visible');").ToString();
if (loadingIsVisible.ToLower() == "false")
break;
Thread.Sleep(1000);
timeout -= 1000;
}
catch (Exception ex)
{
if (!ex.Message.ToLower().Contains("$ is not defined"))
throw;
}
}
}
And the correction:
public void WaitLoadingMessage(int timeout)
{
while (timeout > 0)
{
try
{
var loadingIsVisible = _js.ExecuteScript("return $('#loading-geral').is(':visible');").ToString();
if (loadingIsVisible.ToLower() == "false")
break;
Thread.Sleep(1000);
timeout -= 1000;
}
catch (Exception ex)
{
if (!ex.Message.ToLower().Contains("$ is not defined"))
throw;
break;
}
}
}