【问题标题】:How many times the condition of explicit wait is checked?检查显式等待条件多少次?
【发布时间】:2019-10-10 18:53:53
【问题描述】:

在隐式等待的情况下,如果WebDriver没有立即找到元素,它会等待指定的时间,如果在指定的时间后没有找到元素,则抛出异常。

意味着在隐式等待的情况下,WebDriver 检查元素两次(最大):

  1. 马上
  2. (如果立即找不到,)在指定时间结束时。

但在显式等待的情况下,多久检查一次条件?

我的意思是如果它每秒检查一次条件是否变为真/不为空,或者像隐式等待一样只检查两次?

【问题讨论】:

  • WebDriverWait 默认每 500 毫秒调用一次 ExpectedCondition,直到成功返回。
  • 感谢帮助!!!

标签: selenium selenium-webdriver


【解决方案1】:

默认情况下,它每 500 毫秒检查一次(即轮询)。 所以从源代码中你可以看到 -

public final static long DEFAULT_SLEEP_TIMEOUT = 500;

public WebDriverWait(WebDriver driver, long timeOutInSeconds) {
    this(driver, new SystemClock(), Sleeper.SYSTEM_SLEEPER, timeOutInSeconds, DEFAULT_SLEEP_TIMEOUT);
}

它在内部调用的地方 -

protected WebDriverWait(WebDriver driver, Clock clock, Sleeper sleeper, long timeOutInSeconds,
      long sleepTimeOut) {
    super(driver, clock, sleeper);
    withTimeout(timeOutInSeconds, TimeUnit.SECONDS);
    pollingEvery(sleepTimeOut, TimeUnit.MILLISECONDS);
    ignoring(NotFoundException.class);
  }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-23
    • 2017-02-12
    • 2011-03-31
    • 2023-02-04
    • 2015-04-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多