您还可以使用-
new WebDriverWait(driver, 10).until(ExpectedConditions.invisibilityOfElementLocated(locator));
如果你去通过源的它,你可以看到,无论
NoSuchElementException和
staleElementReferenceException进行处理。
public static ExpectedCondition<Boolean> invisibilityOfElementLocated( final By locator) { return new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver driver) { try { return !(findElement(locator, driver).isDisplayed()); } catch (NoSuchElementException e) { // Returns true because the element is not present in DOM. The // try block checks if the element is present but is invisible. return true; } catch (StaleElementReferenceException e) { // Returns true because stale element reference implies that element // is no longer visible. return true; } }


