0
我在我的try catch块中有2个抓取,但WebDriverTimeoutException根本没有被捕获。另一个例外被正确捕获。超时例外测试失败“OpenQA.Selenium.WebDriverTimeoutException:20秒后超时”尝试抓取WebDriverTimeoutException不起作用
那么为什么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;
}
非常感谢你JimEvans,你的建议真的有效。现在我的方法看起来更小,效率更高。 – Patrick