selenium元素等待
1.强制等待:sleep() 固定等待几秒
2.隐式等待:implicitly_wait() 是webdriver中的方法,设置等待的最大时间,当元素加载出来后就不会再等,超过这个时间就会报错
隐式等待针对脚本内所有的元素进行等待
3.显示等待:WebDriverWait() 在指定时间范围内等待元素,每隔x秒去判断一下指定的元素是否加载完,如果超时则抛出异常。WebDriverWait类一般配合其until()或until_not()方法使用。
WebDriverWait(driver, timeout, poll_frequency=0.5, ignored_exceptions=None).until(method, message='')
from selenium.webdriver.support import expected_conditions as EC
WebDriverWait(driver, 30, poll_frequency=0.5).until(EC.element_to_be_clickable("xpath", "//input[@id='kw']")

浙公网安备 33010602011771号