We are using Selenium with C#. We have a driver script where we instantiate the driver and then we call a testscript (automated functional testcase flow). Everything works well when the object is present on the page. We are facing issue of driver getting killed when we try and verify that certain object is not present, below is the code
Driver Script Code
//driver = new RemoteWebDriver(new Uri(uri), capabilites,TimeSpan.FromSeconds(120));
Test Script Code
public class GraphNew
{
public Boolean testGraphNew(IWebDriver driver, Logger OneLogger)
{
try
{ //Navigate to a page
try
{
driver.FindElement(By.XPath("//a[contains(text(),'Add New Claim')]")).Click();
}
catch
{
OneLogger.Log("Element is not prsent")
}
}
}
catch(Exception e)
{
OneLogger.LogException(e);
return false;
}
}
The problem is when the object is not identified (as it is not present) in the inner try, rather than going to the inner catch block, the execution proceeds to outer catch and shows exception as -
{"The HTTP request to the remote WebDriver server for URL http://localhost:4449/wd/hub/session/35c483a6-6871-425a-a936-aeebb0742fd2/element timed out after 120 seconds."}
and driver gets killed.
Can anyone please suggest, if we are missing something or what should be the idle way to code so that once the object is not identified, driver does not get killed and execution continues for the remaining code.