#在设定时间(timeout)内,每隔poll_frequency,执行一次until里面的函数
WebDriverWait(driver,timeout=5,poll_frequency=0.5,
ignored_exceptions=None).until()
比如:
ele=WebDriverWait(driver,5,0.5).until(
expected_conditions.presence_of_element_located(By.ID,'kw'))
expected_conditions常用函数
from selenium.webdriver.support import expected_conditions expected_conditions.title_is(title=) #判断当前页面标题是否等于预期 expected_conditions.title_contains(title=) #是否包含预期字符串 expected_conditions.presence_of_element_located(locator=) #元素是否被加在DOM树里面,并不代表一定可见 expected_conditions.presence_of_all_elements_located(locator=) #判断是否至少有一个 expected_conditions.visibility_of_element_located(locator=) #判断可见 expected_conditions.visibility_of(element=) #判断可见 expected_conditions.text_to_be_present_in_element(locator=,text_=) #text中是否包含字符串 expected_conditions.text_to_be_present_in_element_value(locator=,text_=) #某个元素的value属性是否包含预期字符串 expected_conditions.frame_to_be_available_and_switch_to_it(locator=) #判断该表单是否能切换进去,能返回true并切换进去 expected_conditions.invisibility_of_element_located(locator=) #判断不存在DOM或不可见 expected_conditions.element_to_be_clickable(locator=) #可点击 expected_conditions.staleness_of(element=) #等到一个元素从DOM移除 expected_conditions.element_located_to_be_selected(locator=) #元素可以被选择,一般用于下拉列表 expected_conditions.element_selection_state_to_be(element=,is_selected=) #元素选中状态是否符合预期 expected_conditions.element_located_selection_state_to_be(locator=,is_selected=) #元素选中状态 expected_conditions.alert_is_present() #是否有alert