为了账号安全,请及时绑定邮箱和手机立即绑定

为什么fluentWait()速度慢?

为什么fluentWait()速度慢?

qq_花开花谢_0 2021-05-03 20:30:01
我fluentWait()在我的selenium代码上使用。但是我注意到,尽管需要等待的元素已经加载到浏览器中,但仍在等待一段时间。这浪费很多时间,但我不知道原因。有谁知道为什么吗?
查看完整描述

1 回答

?
蝴蝶不菲

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);

因此,这取决于您将使用什么。


查看完整回答
反对 回复 2021-05-19
  • 1 回答
  • 0 关注
  • 223 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信