【问题标题】:WebDriverWait timeout waits for the driver implicit timeout instead of the explicit timeout providedWebDriverWait 超时等待驱动程序隐式超时而不是提供的显式超时
【发布时间】:2016-04-05 14:04:57
【问题描述】:

我正在使用 python 和 Selenium WebDriver 来测试基于角度的网络应用程序。

在登录助手子例程中,登录时,我想在继续其余测试之前检查它是否成功。

为此,我有以下代码:

login_success = WebDriverWait(self.driver,5).until(EC.visibility_of_element_located((By.CLASS_NAME,"hr-landing")))

if login_success:
    self.logger.info("Looks like login was successful")
else:
    login_errors = self.get_login_errors()
    self.logger.debug(login_errors)

我面临的问题是代码的第一行。对于成功登录,它会在找到类 'hr-landing' 时快速返回。

但是,对于失败的登录,找不到该类,我希望等待在 5 秒内超时,如我对 WebDriverWait 的调用中指定的那样。

但是,调用仅在 30 秒后超时(这是我在驱动程序上设置的隐式等待)

我该如何解决这个问题?我觉得提供显式超时没有意义,因为它仍然尊重隐式超时。

非常感谢! 莫兹。

【问题讨论】:

  • get_login_errors 包含隐式等待?
  • 我在测试工具开始时调用 self.driver.implicitly_wait(30) 一次——等待设置在我的登录方法中持续存在——不仅持续存在,而且优先于提供给 WebDriverWait 的显式等待

标签: selenium-webdriver


【解决方案1】:

这是我们在同时使用隐式和显式等待时通常面临的问题。失败时调用 get_login_errors(),所以我希望它有隐式等待。

为了避免此类问题,我希望能够很好地使用流畅的等待,这解释了here

谢谢你, 壁画

【讨论】:

  • 有没有相当于 fletnwait 的 python?
  • Hi 看起来 fluentwait 在 python 中不可用。在同一链接中,python 有办法通过显式等待来检查元素。 def conditions(driver): flag = True ticker = driver.find_elements_by_id("textbox") if not ticker: flag = False return flag ... 单击要加载的内容 ... self.wait = WebDriverWait(driver, timeout) self.等待.直到(条件)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-20
  • 2015-10-11
  • 2019-12-28
相关资源
最近更新 更多