简体   繁体   English

询问预期条件

[英]Ask About ExpectedConditions

   public static IWebElement WaitGetElement(IWebDriver driver, By by, int timeoutInSeconds, bool checkIsVisible = false)
    {
        WebDriverWait webDriverWait = new WebDriverWait(driver, TimeSpan.FromSeconds((double)timeoutInSeconds));
        IWebElement result;
        try
        {
            if (checkIsVisible)
            {
                result = webDriverWait.Until<IWebElement>(ExpectedConditions.ElementIsVisible(by));
            }
            else
            {
                result = webDriverWait.Until<IWebElement>(ExpectedConditions.ElementExists(by));
            }
        }
        catch (NoSuchElementException)
        {
            result = null;
        }
        catch (WebDriverTimeoutException)
        {
            result = null;
        }
        catch (TimeoutException)
        {
            result = null;
        }
        return result;
    }

This is My Code .这是我的代码。 It Give Me Erro : The name 'ExpectedConditions' does not exist in the current context .它给我错误:当前上下文中不存在名称“ExpectedConditions”。 Can you Help Me .你能帮助我吗 。

I Think you are missing this particular Nuget package "SeleniumExtras.WaitHelpers.ExpectedConditions" https://www.nuget.org/packages/DotNetSeleniumExtras.WaitHelpers/3.11.0我认为你错过了这个特殊的 Nuget 包“SeleniumExtras.WaitHelpers.ExpectedConditions” https://www.nuget.org/packages/DotNetSeleniumExtras.WaitHelpers/3.11.0

You can download it from nuget library or with the link provided.您可以从 nuget 库或使用提供的链接下载它。 Later as some comments tell you must put an "using" in the code.后来有些评论告诉您必须在代码中放置一个“使用”。

I hope this helps我希望这有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM