隐式等待(智能等待):
driver.implicitly_wait()
全局变量
等待一个元素被发现或一个命令被完成,超过等待时间抛出异常
详情:https://blog.csdn.net/wycaoxin3/article/details/74017971
显示等待:
明确要等待某个元素出现或命令完成,每规定时间执行一次,直到超过规定时间,抛出异常
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
#WebDriverWait(driver,timeout,poll_frequency=0.5,ignored_exceptions=None)
element = WebDriverWait(driver,30).until(lambda x:x.find_element_by_id('id'))
element.send_keys('')
locator = (By.ID,'kw')
WebDriverWait(driver,30).until_not(EC.presence_of_element_located(locator)
from selenium.webdriver.support import expected_conditions as EC
expected_conditions模块
title_is :判断当前页面title
title_contains:判断title是否包含预期字符串
presence_of_element_located:判断某元素是否被加到dom数,并不代表该元素一定可见
visibility_of_element_located:判断元素是否可见,可见代表元素非隐藏,并且宽和高非0
visibility_of:判断元素是否可见,只需要传定位element
presence_of_all_elements_located:判断至少有一个此元素
text_to_be_present_in_element:判断某元素中text是否包含预期字符串
text_to_be_present_in_element_value:判断某元素中value属性是否包含预期字符串
frame_to_be_available_and_switch_to_it:判断frame是否可以switch进去
invisibility_of_element_located:判断某元素是否不存在于dom树或不可见
element_to_be_clickable:判断元素是否可见且是可点击的
element_to_be_selected:判断元素是否被选中,下拉框
element_selection_state_to_be:判断元素选中状态是否符合预期
element_located_selection_state_to_be:判断元素选中状态是否符合预期,传入locator
alert_is_present:判断页面上是否存在alert