I want to make sure that an element is present before the webdriver starts doing stuff.
I\'m trying to get something like this to work:
WebDriverWait w
This is the reusable function to wait for an element present in DOM using Explicit Wait.
public void WaitForElement(IWebElement element, int timeout = 2)
{
WebDriverWait wait = new WebDriverWait(webDriver, TimeSpan.FromMinutes(timeout));
wait.IgnoreExceptionTypes(typeof(NoSuchElementException));
wait.IgnoreExceptionTypes(typeof(StaleElementReferenceException));
wait.Until(driver =>
{
try
{
return element.Displayed;
}
catch (Exception)
{
return false;
}
});
}