Check the invisibilityOfElementLocated
expected condition. Reference. From the doc:
invisibilityOfElementLocated public static ExpectedCondition<java.lang.Boolean> invisibilityOfElementLocated(By locator) An expectation for checking that an element is either invisible or not present on the DOM. Parameters: locator - used to find the element
So you could use it like:
public void waitForInvisibility(WebDriver webDriver, String cssToWaitFor) {
WebDriverWait wait = new WebDriverWait(webDriver, 20);
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector(cssToWaitFor)));
}
Alternatively you can look into public static ExpectedCondition<java.lang.Boolean> not(ExpectedCondition<?> condition)
, which by the doc does:
An expectation with the logical opposite condition of the given condition.