为了检查元素是否存在并且可点击,我尝试编写一个布尔方法,该方法将等待元素启用并使用 C# selenium webDriverWait 显示,如下所示:
webDriverWait wait = new webDriverWait(driver, timeSpan.fromSeconds(60));
Wait.untill( d => webElement.enabled() && webElement.displayed());
如果上述条件没有发生,我希望该方法返回“false”。问题是我抛出异常。
如果抛出 noSuchElementException 和 timeOutException 等异常,如何忽略它们?
我尝试使用 try catch 块,但它没有帮助,并且引发了异常。
WebDriverWait
实施DefaultWait
包含的类public void IgnoreExceptionTypes(params Type[] exceptionTypes)
method.
您可以使用此方法来定义在单击之前等待元素启用时要忽略的所有异常类型。
例如 :
WebDriverWait wdw = new WebDriverWait(driver, TimeSpan.FromSeconds(120));
wdw.IgnoreExceptionTypes(typeof(NoSuchElementException), typeof(ElementNotVisibleException));
在前面的代码中, wait 将忽略 NoSuchElementException 和 ElementNotVisibleException 异常
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)