导入模块
from selenium import webdriver
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.by import By
基本格式
WebdriverWait(驱动,等待时间).until(method) 直到方法为True
WebdriverWait(驱动,等待时间).not_until(method) 直到方法为False
运用
locator=(By.ID,'元素ID号')
driver=webdriver.Chrome()
driver.get(url)
WebdriverWait(driver,10).until(expected_conditions.visibility_of_element_located(locator))
其他常用状态
.element_to_be_clickable(locator) 元素可以点击
.visibility_of_element_located(locator) 元素可见的时候(html结构中已有)
.presence_of_element_located(locator) 元素呈现的时候
.title_contains(文字)
.title_is(文字)
.alert_is_present() 消息框呈现