I am running a test using Selenium WebDriver and if a user doesn't have access rights a div does not exist on the page. I am trying to do a wait so that if the item is displayed it returns true but if it hits the timeout it returns false.
public bool SummaryDisplayed()
{
var wait = new WebDriverWait(_driver, TimeSpan.FromSeconds(5));
var myElement = wait.Until(x => x.FindElement(By.Id("summaryPage")));
return myElement.Displayed;
}
I don't want to use Thread.Sleep because if the element is there after 2 seconds I want it to proceed. But if the element isn't there after 5 seconds it should return false. I don't want it to throw an exception, in some test cases I am expecting it to not exist. Is there a way I can suppress the exception and return false after the timeout? Thanks