selenium---三种等待方式
-
强制等待
强制等待,让线程休眠一段时间
time.sleep(5)隐式等待
-
隐式等待
设置一个等待时间,轮询查找(默认0.5秒)元素是否出现,元素找到后立刻停止轮询,如果元素没有出现就抛出异常。
隐式等待是针对于全局的
self.driver.implicitly_wait(5)
-
显示等待
WebDriverWait,配合该类的until()和until_not()方法,就能够根据判断条件而进行灵活地等待了。它主要的意思就是:程序每隔xx秒(默认为0.5秒)看一眼,如果条件成立了,则执行下一步,否则继续等待,直到超过设置的最长时间,然后抛出TimeoutException。
from selenium.webdriver.support import expected_conditions from selenium.webdriver.support.wait import WebDriverWait WebDriverWait(self.driver, 10).until(expected_conditions.element_located_to_be_selected(locator))

浙公网安备 33010602011771号