首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WebDriverWait不会忽略异常

WebDriverWait不会忽略异常
EN

Stack Overflow用户
提问于 2013-08-21 23:18:58
回答 2查看 8.8K关注 0票数 7

我使用的是最新的Chrome和Webdriver 2.33,在使用IgnoreExceptionTypes时遇到了一些问题。在下面的代码中,webdriver也会像我预期的那样等待,但它实际上不会忽略异常:

代码语言:javascript
复制
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(8));
wait.IgnoreExceptionTypes(
    typeof(WebDriverTimeoutException),
    typeof(NoSuchElementException)
);  
wait.Until(ExpectedConditions.ElementIsVisible(By.XPath(firstResultX)));

代码在try/catch中,我尝试将它移到try/catch之外,但收到了同样的问题。我不知道从这里到哪里去,任何帮助都将不胜感激。

EN

回答 2

Stack Overflow用户

发布于 2014-08-30 14:30:13

您可以使用FluentWaits。

代码语言:javascript
复制
Wait<WebDriver> wait = new FluentWait<WebDriver>(getDriverInstance())
                .withTimeout(timeoutSeconds, TimeUnit.SECONDS)
                .pollingEvery(sleepMilliSeconds, TimeUnit.SECONDS)
                .ignoring(NoSuchElementException.class);

wait.until(<Your expected condition clause.>);

如果这不能解决您的问题,请让我知道。

票数 1
EN

Stack Overflow用户

发布于 2021-03-30 18:35:25

对于C#,不同的等待是-

代码语言:javascript
复制
      ` //Implicit Wait - Once set it remains till the life of the session
        Driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);

        //Explicit Wait - Polling interval is 250ms
        //using OpenQA.Selenium.Support.UI; 
        WebDriverWait wait = new WebDriverWait(Driver, TimeSpan.FromSeconds(30));
        //this wait utility ignores no such element errors by default
        IWebElement webElement = wait.Until(e => e.FindElement(By.Id("value")));

        //Fluent wait - Polling interval is set by us
        WebDriverWait fluentWait = new WebDriverWait(Driver, TimeSpan.FromSeconds(30))
        {
            PollingInterval = TimeSpan.FromSeconds(2)
        };
        fluentWait.IgnoreExceptionTypes(typeof(AccessViolationException), typeof(NoSuchElementException));
        IWebElement element = wait.Until(e => e.FindElement(By.Id("value")));`
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18361362

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档