invisibilityOf()
invisibilityOf(WebElement element)
is defined as:
public static ExpectedCondition<java.lang.Boolean> invisibilityOf(WebElement element)
An expectation for checking the element to be invisible
Here the expectation is that, the element must be present as well as visible as a pre-condition and the method will wait for the element to be invisible. At this point it is worth to mention that as the argument is of type WebElement, findElement(By by)
have to successfully locate the element as a pre-condition. Hence NoSuchElementException
can't be ignored.
invisibilityOfElementLocated()
invisibilityOfElementLocated(By locator)
is defined as:
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.
Here the expectation is clearly either the element is already invisible or not present in the HTML DOM. In this case the primary mission is the absence of the element which may occur even before the ExpectedCondition is invoked or during the timespan while the ExpectedCondition is active. So here we need to ignore NoSuchElementException
as a mandatory measure.
This usecase
To pause the execution of your program you need to induce WebDriverWait and you can use either of the following Locator Strategies:
Using invisibilityOf()
:
new WebDriverWait(driver, 20).until(ExpectedConditions.invisibilityOf(driver.findElement(By.xpath("//div[@class='ngx-loading-text center-center' and starts-with(., 'Loading')]"))));
Using invisibilityOfElementLocated()
:
new WebDriverWait(driver, 20).until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//div[@class='ngx-loading-text center-center' and starts-with(., 'Loading')]")));
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…