我想确保给定元素不在DOM中,或者如果它存在于DOM中,则不再显示。
为了这样做,我将WebDriverWait
配置为忽略NoSuchElementException
和:
public static void WaitForElementToDisappear(IWebDriver driver)
{
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(20));
wait.IgnoreExceptionTypes(typeof(OpenQA.Selenium.NoSuchElementException));
wait.Until(d => d.FindElement(By.ClassName("ClassName")).Displayed == false);
}
不幸的是,这种兴奋并没有被忽略,一旦抛出,测试就会失败。
如何处理?
编辑:我发现不幸的是,这是期望的等待行为,直到超时都不会引发异常,所以我的方法是绝对错误的。
您为什么不使用现有的ExpectedConditions
?
wait.Until(ExpectedConditions.InvisibilityOfElementLocated(By.ClassName("ClassName")));