Selenium - Wait until element is NOT visible

后端 未结 10 2101
生来不讨喜
生来不讨喜 2021-02-02 07:29

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         


        
10条回答
  •  逝去的感伤
    2021-02-02 08:23

    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);
        }
    }
    

提交回复
热议问题