In the code below, I attempt to wait until an element is visible:
var wait = new WebDriverWait(Driver.Instance, TimeSpan.FromSeconds(10));
wait.Until(ExpectedCon
I know this is old, but since I was searching for a solution to this, I thought I'd add my thoughts.
The answer given above should work if you set the IgnoreExceptionTypes property:
var wait = new WebDriverWait(Driver.Instance, TimeSpan.FromSeconds(10));
wait.IgnoreExceptionTypes = new[] { typeof(NoSuchElementException) }
wait Until(driver => !driver.FindElement(By.Id("processing")).Displayed);
var wait = new WebDriverWait(Driver.Instance, TimeSpan.FromSeconds(10));
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id("processing")));
The idea is to wait until element is not visible. First line sets wait time that element has to disappear; here it's 10 seconds. Second line uses selenium to check if condition "invisibilityofElementLocated" is met. Element is found by its id as in topic case, that is id="processing"
. If element doesn't disappear in the requested period of time, a Timeout exception will be raised and the test will fail.
In the code below which is used to stop the driver for couple of seconds
System.Threading.Thread.Sleep(20000);
Use invisibility method, and here is an example usage.
final public static boolean waitForElToBeRemove(WebDriver driver, final By by) {
try {
driver.manage().timeouts()
.implicitlyWait(0, TimeUnit.SECONDS);
WebDriverWait wait = new WebDriverWait(UITestBase.driver,
DEFAULT_TIMEOUT);
boolean present = wait
.ignoring(StaleElementReferenceException.class)
.ignoring(NoSuchElementException.class)
.until(ExpectedConditions.invisibilityOfElementLocated(by));
return present;
} catch (Exception e) {
return false;
} finally {
driver.manage().timeouts()
.implicitlyWait(DEFAULT_TIMEOUT, TimeUnit.SECONDS);
}
}