大佬教程收集整理的这篇文章主要介绍了如何等待selenium中是否存在元素?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
需要等待ignoring
时,您需要异常调用以忽略WebDriver
。
FluentWait<WebDriver> fluentWait = new FluentWait<>(driver)
.withTimeout(30, TimeUnit.SECONDS)
.pollingEvery(200, TimeUnit.MILliSECONDS)
.ignoring(NoSucHelementexception.class);
有关更多信息,请参见FluentWait的文档。但是请注意,此条件已在ExpectedConditions中实现,因此您应该使用
WebElement element = (new webdriverwait(driver, 10))
.until(ExpectedConditions.elementToBeClickable(By.ID("somEID")));
*更新为更新版本的SELEnium:
withTimeout(long, TimeUnit) has become withTimeout(Duration)
pollingEvery(long, TimeUnit) has become pollingEvery(Duration)
因此,代码将如下所示:
FluentWait<WebDriver> fluentWait = new FluentWait<>(driver)
.withTimeout(Duration.ofSeconds(30)
.pollingEvery(Duration.ofMillis(200)
.ignoring(NoSucHelementexception.class);
等待的基本教程可以在这里找到。
我试图让SELEnium等待页面加载后动态添加到DOM的元素。试过这个:
fluentWait.until(ExpectedConditions.presenceOfElement(By.id("elementId"));
如果有帮助,这里是fluentWait
:
FluentWait fluentWait = new FluentWait<>(webDriver) {
.withTimeout(30,TimeUnit.SECONDS)
.pollingEvery(200,TimeUnit.MILLISECONDS);
}
但是它抛出一个NoSucHelementexception
-看起来像presenceOfElement
期望元素存在,所以这是有缺陷的。这一定是SELEnium的面包和黄油,不想重新发明轮子……有人能建议一种替代方法PreDicate
吗,理想情况下不用自己动手做?
以上是大佬教程为你收集整理的如何等待selenium中是否存在元素?全部内容,希望文章能够帮你解决如何等待selenium中是否存在元素?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。