显示等待:对某一个元素等待
隐式等待:对全局元素等待
WebDriverWait 显示等待针对元素比用
expected conditions预期条件类,包含方法、用于显示等待
NoSuchElementException 用于隐式等待抛出异常
by 用于元素定位
显示等待
引入类
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
element=WebDriverWait(driver,5,0.5).until(EC.presence_of_element_located((By.ID,"123")))
5,0.5 最长等待时间(秒),时间间隔(毫秒)
elemnet= WebDriverWait(参数).until( EC.条件实现((By类定位方式, 定位值), message))
隐式等待
引入类
from selenium.common.exceptions import NoSuchElementException
示例:
driver.implicitly_wait(5) 当前全局元素等待5秒后继续