Selenium - Wait until element is NOT visible

后端 未结 10 2092
生来不讨喜
生来不讨喜 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 07:58

    public void WaitForElementNotVisible(string id, int seconds)
        {
    
            try
            {
                var wait = new OpenQA.Selenium.Support.UI.WebDriverWait(driver, TimeSpan.FromSeconds(seconds));                   
                wait.Until(driver1 => !visibility(id));
                Console.WriteLine("Element is not visible..");
            }
            catch (WebDriverTimeoutException)
            {
                Assert.Fail("Element is still visible..");
            }
    
    
        }
    
    
        bool visibility(string id)
        {
            bool flag;
            try
            {
                flag = driver.FindElement(By.Id(locator)).Displayed;
            }
            catch (NoSuchElementException)
            {
                flag = false;
            }
            return flag;
        }
    

提交回复
热议问题