【发布时间】:2022-01-21 14:01:42
【问题描述】:
在 try / catch 块中使用 wait.Until() 时,如果元素不存在,则会引发 NoSuchElementException 异常。但是,当我尝试捕获异常时,仍然会收到错误消息。
try
{
wait.Until(el => el.FindElement(By.Id("courseTestItem")));
driver.Close();
driver.SwitchTo().Window(driver.WindowHandles.Last());
Console.WriteLine("Skipped: " + courses[0].Item1.Text + " (Has test)");
}
catch (OpenQA.Selenium.NoSuchElementException) { }
我什至尝试只使用catch (Exception e) { },但仍然没有发现错误。
【问题讨论】: