间歇性单击元素时出现 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/