【发布时间】:2021-10-22 16:59:38
【问题描述】:
以下代码不起作用。 selenium web 驱动程序无需等待即可继续执行,即使页面上的任何元素都不可见。因此断言失败。
element = WebDriverWait(self.driver, 30).until(
lambda x: (EC.visibility_of_element_located((By.ID, "export_errors_button"))) or
(EC.visibility_of_element_located((By.ID, "finish_button")))
)
assert "finish_button" in element.get_attribute('id').split()
【问题讨论】:
-
表示你的ids确实存在于页面上,因此它不会等待,没有暂停之类的东西,不推荐使用thread.sleep,所以我有一个小技巧使用其实就是等待一个不存在的元素并捕获异常
-
请您详细说明一下。我也在检查它们的可见性,而不是它们的存在。
-
EC.presence_of_element_located()产生相同的结果? -
在 HTML DOM 中可见吗? Selenium 与 HTMLDOM 的交互与您在 UI 中看到的不同。
-
EC.presence_of_element_located() 产生相同的结果。两个元素都设置为 style="display:none"。
标签: selenium selenium-webdriver implicitwait