WebDriverWait does not ignore exceptions

血红的双手。 提交于 2020-01-24 03:16:29

问题


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)));

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.


回答1:


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.



来源:https://stackoverflow.com/questions/18361362/webdriverwait-does-not-ignore-exceptions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!