0
When I try to check if an element exists or not on my website and if the element does not exist, my Iwebdriver launches a Webdriverexception, and all of my driver’s methods stop working, making it impossible for me to continue with the test running even while doing the treatment to return null or 0 in a catch.
I would like to remind you the verification method I’m using is in the Selenium documentation, saying to use Findelements instead of Findelement: findElement should not be used to look for non-present elements, use WebDriver.findElements(By) and assert zero length response instead.
I’m using the latest version of Selenium Webdriver and Chromedriver for C#.
Error reported in Exception: [OpenQA.Selenium.WebDriverException]
The HTTP request to the remote WebDriver server for URL http://localhost:18144/session/5eeb22629a0d6f35b829113728c3f5a7/elements timed out after 60 seconds.`
Method I use to verify whether or not an element exists:
public IWebElement SafeFindElement(By by)
{
try
{
var element = _driver.FindElements(by);
return element.FirstOrDefault();
}
catch (NoSuchElementException)
{
return null;
}
catch (Exception)
{
return null;
}
}