WebDriverWait不会忽略异常 [英] WebDriverWait does not ignore exceptions

查看:70
本文介绍了WebDriverWait不会忽略异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am using the most current Chrome and Webdriver 2.33 and am having some issues with IgnoreExceptionTypes. In the below code webdriver will wait like I expect it too but it will not actually ignore the exceptions:

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之外,并收到相同的问题.我不确定从这里去哪里,将不胜感激.

The code is in a try/catch, I tried moving it outside of the try/catch and received the same issue. I am not sure where to go from here, any help would be appreciated.

推荐答案

您可以使用FluentWaits.

You can use FluentWaits.

Wait<WebDriver> wait = new FluentWait<WebDriver>(getDriverInstance())
                .withTimeout(timeoutSeconds, TimeUnit.SECONDS)
                .pollingEvery(sleepMilliSeconds, TimeUnit.SECONDS)
                .ignoring(NoSuchElementException.class);

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

让我知道这是否不能解决您的问题.

Let me know if this does not solves your problem.

这篇关于WebDriverWait不会忽略异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆