python - EC.element_to_be_clickable 和 EC.presence_of_element_located to click() 一个元素的区别

标签 python selenium selenium-webdriver expected-condition

间歇性单击元素时出现 TimeoutExceptions。我尝试过显式等待和 time.sleep()。它工作了一段时间,我再次得到异常(exception)。

我想了解它是否是由预期条件引起的。

WebDriverWait(self.driver, 40).until(EC.element_to_be_clickable((By.XPATH, <locator>  ))).click()

如果我使用以下条件,是否有助于避免超时异常?
element = WebDriverWait(self.driver, 40).until(EC.presence_of_element_located((By.XPATH, <locator>  )))
element.click()

最佳答案

基于 selenium 的官方文档和代码实现。
presence_of_element_located(locator) 定义:

An expectation for checking that an element is present on the DOM of a page. This does not necessarily mean that the element is visible. locator - used to find the element returns the WebElement once it is located


element_to_be_clickable(locator) :

An Expectation for checking an element is visible and enabled such that you can click it.


预期条件在定义的超时期限内循环执行条件。它将轮询直到 true返回条件。如 false返回,它将继续循环,直到达到最大超时。

关于python - EC.element_to_be_clickable 和 EC.presence_of_element_located to click() 一个元素的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61494149/

相关文章:

java - 如何在 Selenium 中启用弹出窗口

webdriver - Selenium 2 - 设置 IE 和 Chrome 的用户代理

python - 标记 3D 参数图中的某些点

java - 使用 findelements 时如何从 xpath 获取文本

python - 如何在不关闭浏览器的情况下在 Google Colab 上使用 Selenium?

python - 无法在 python selenium 脚本中使用具有特殊字符 '$' 的密码

java - Selenium 3.12 在 driver.quit() @ FireFox 60/Win 7 Home Premium/Java 10.0.1/GeckoDriver 0.20.1 上显示错误

python - 对字符串中与正则表达式模式不匹配的所有部分进行操作的函数

Python树结构字典创建问题

python - python中的if/else语法错误