【发布时间】:2016-12-24 01:42:36
【问题描述】:
我的 try catch 块中有 2 个捕获,但是 WebDriverTimeoutException 根本没有被捕获。另一个异常被正确捕获。测试因超时异常“OpenQA.Selenium.WebDriverTimeoutException :Timed out after 20 seconds”而失败
那么为什么 WebDriverTimeoutException try catch 根本没有被捕获?
public IWebElement FindElement(By howBy)
{
TimeSpan _elementTimeOut = TimeSpan.FromSeconds(20);
IWebElement elementfound = null;
WebDriverWait wait = new WebDriverWait(WebDriver, _elementTimeOut);
wait.Until<IWebElement>(d =>
{
try
{
elementfound = WebDriver.FindElement(howBy);
}
catch (WebDriverTimeoutException f)
{
Console.WriteLine("Please fail WebDriverTimeoutException");
}
catch (NoSuchElementException e)
{
Console.WriteLine("Please fail NoSuchElementException");
}
return elementfound;
});
return elementfound;
}
【问题讨论】:
标签: c# selenium-webdriver