C# Selenium 'ExpectedConditions is obsolete'

前端 未结 7 1678
灰色年华
灰色年华 2020-11-28 04:51

When trying to explicitly wait for an element to become visible using ExpectedConditions, Visual Studio warns me that it is now obsolete and will be removed from Selenium so

相关标签:
7条回答
  • 2020-11-28 05:40

    If you don't want to download an extra nuget package, it is quite easy to declare your own function (or condition), especially using a lamda expression, e.g.

    var wait = new WebDriverWait(driver, new TimeSpan(0, 0, 30));
    var element = wait.Until(condition =>
    {
        try
        {
            var elementToBeDisplayed = driver.FindElement(By.Id("content-section"));
            return elementToBeDisplayed.Displayed;
        }
        catch (StaleElementReferenceException)
        {
            return false;
        }
        catch (NoSuchElementException)
        {
            return false;
        }
    });
    

    This is also very versitile, since it is now possible to evaluate any kind of bool-expression.

    0 讨论(0)
提交回复
热议问题