我使用的是最新的Chrome和Webdriver 2.33,在使用IgnoreExceptionTypes时遇到了一些问题。在下面的代码中,webdriver也会像我预期的那样等待,但它实际上不会忽略异常:
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之外,但收到了同样的问题。我不知道从这里到哪里去,任何帮助都将不胜感激。
发布于 2014-08-30 14:30:13
您可以使用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.>);如果这不能解决您的问题,请让我知道。
发布于 2021-03-30 18:35:25
对于C#,不同的等待是-
` //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")));`https://stackoverflow.com/questions/18361362
复制相似问题