I updated my framework and this method I have used for “is element present” broke and I am not sure why?? When the element is found, no issue and it returns true. When the element is not found, instead of returning false, it throws the below error and fails the test case.
Any ideas what I am missing here?
OpenQA.Selenium.NoSuchElementException: 'no such element: Unable to locate element: {"method":"xpath","selector":"//my[@id='xpath']"}
Element locator
public const string eleVal = "//my[@id='xpath']";
public IWebElement _eleVal { get { return Browser.Driver.FindElement(By.XPath(eleVal )); } }
Method to get status. It fails on this when the element is not not found.
public bool GetValue()
{
bool ele = Driver.IsElementPresent(_eleVal);
if(ele)
{
return true;
}
else
{
return false;
}
}
method that has always worked
public static bool IsElementPresent(IWebElement element)
{
bool result;
try
{
result = element.Displayed;
}
catch (NoSuchElementException)
{
return false;
}
catch (StaleElementReferenceException)
{
return false;
}
catch (WebDriverException)
{
return false;
}
return result;
}