我有这个函数通过css选择器找到一个元素并等待它可以点击:
def wait_for_element_clickable(cls, selector, timeout=10, parent=None):
""" wait for an element to be clickable """
if parent is None:
parent = cls.driver
wd_wait = WebDriverWait(parent, timeout)
# Wait for it to be visible too.
cls.wait_for_element(selector=selector, parent=parent)
wd_wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, selector)),
'waiting for element to be clickable ' + selector)
return parent.find_element_by_css_selector(selector)
现在我的情况是我已经有了一个WebElement,我只想等待它可以点击。有没有办法在现有的WebElement上使用EC.element_to_be_clickable?
答案 0 :(得分:2)
element_to_be_clickable
没有为Python中的WebElement重载(尽管它有Java和C#)。但是你可以自己编写
class element_to_be_clickable(object):
def __init__(self, element):
self.element = element
def __call__(self, driver):
return element.is_displayed() and element.is_enabled()
用途
wd_wait.until(element_to_be_clickable(element))