问题
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