2013-08-21 112 views
4

我正在使用最新的Chrome和Webdriver 2.33,并且在IgnoreExceptionTypes中遇到了一些问题。在下面的代码的webdriver等待像我希望如此,但它实际上并不会忽略例外:WebDriverWait不会忽略异常

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语句之外,并获得同样的问题。我不确定该从哪里出发,任何帮助将不胜感激。

+0

检查http://sqa.stackexchange.com/a/5096/5773 ...也许这会对你有所帮助 – Sankumarsingh

+0

感谢您的链接。我查了一下,看起来这个人有同样的问题,我和他的问题没有得到解决。重申这个问题是,尽管提供了正确类型的IgnoreExceptionTypes,但我的自动化仍然会引起我让它忽略的错误。 – hhcib

+0

我刚刚结束了尝试赶上wait.Until电话。同样的事情,IgnoreExceptionTypes似乎什么也不做,或者至少不是我所期望的。 – mrfreester

回答

0

您可以使用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.>); 

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