我正在使用Python 2.7中的selenium,我有这段代码,但我正在寻找更有效的方法来完成这个任务:
while True:
try:
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, 'button'))
)
except:
break
element = WebDriverWait(driver, 10).until(
EC.invisibility_of_element_located((By.ID, 'button')))
您不需要使用 while 循环,因为 WebDriverWait() 函数已经等待了您设置的时间。
1) 使用预期条件中的staleness_of
class staleness_of(object):
""" Wait until an element is no longer attached to the DOM.
element is the element to wait for.
returns False if the element is still attached to the DOM, true otherwise.
"""
2) WebDriverWait(driver, 10).until_not(...)