我fluentWait()在我的selenium代码上使用。但是我注意到,尽管需要等待的元素已经加载到浏览器中,但仍在等待一段时间。这浪费很多时间,但我不知道原因。有谁知道为什么吗?
1 回答
![?](http://img1.sycdn.imooc.com/5333a0780001a6e702200220-100-100.jpg)
蝴蝶不菲
TA贡献1810条经验 获得超4个赞
每个FluentWait实例都定义了等待条件的最长时间,以及检查条件的频率。此外,用户可以配置等待以在等待时忽略特定类型的异常,例如在页面上搜索元素时的NoSuchElementExceptions。
// Waiting 30 seconds for an element to be present on the page, checking
// for its presence once every 5 seconds.
Wait wait = new FluentWait(driver)
.withTimeout(30, SECONDS)
.pollingEvery(5, SECONDS)
.ignoring(NoSuchElementException.class);
会变慢,因为:
// Waiting 30 seconds for an element to be present on the page, checking
// for its presence once every 1 second.
Wait wait = new FluentWait(driver)
.withTimeout(30, SECONDS)
.pollingEvery(1, SECONDS)
.ignoring(NoSuchElementException.class);
因此,这取决于您将使用什么。
添加回答
举报
0/150
提交
取消