我在Python 2.7中使用selenium并且我有这个代码,但我正在寻找一种更有效的方法来实现这一点:
while True:
try:
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, 'button'))
)
except:
break
答案 0 :(得分:9)
element = WebDriverWait(driver, 10).until(
EC.invisibility_of_element_located((By.ID, 'button'))
你不需要使用while。它已经等待你在WebDriverWait()函数中出现的时间。
答案 1 :(得分:7)
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(...)