from selenium import webdriver
from time import sleep
from selenium.webdriver.support.expected_conditions import *
from selenium.webdriver.support.wait import WebDriverWait
wb=webdriver.Chrome()
wb.get("https://www.baidu.com/home")
wb.maximize_window()
sleep(1) #强制等待,适用于特定的元素
wb.implicitly_wait(2) #隐式等待,适用于全局元素.只需要在全局设定一次即可
#显示等待
#web元素或布尔值=WebDriverWait(浏览器对象,等待时间,轮询时间).until(元素查找期待条件)
wb0=WebDriverWait(wb,10,1).until(visibility_of_element_located(("id","su")))
#visibility_of_element_located("id","su"),判断某个元素是否可见,找到返回元素对象
wb0.send_keys("今日头条")
wb1=WebDriverWait(wb,10,1).until(presence_of_element_located(("id","su")))
#presence_of_element_located("id","su") 判断某个元素是否被加载到页面,找到返回元素对象
wb8=WebDriverWait(wb,10,1).until(element_to_be_clickable(("id","su")))
#element_to_be_clickable(("id","su")) 判断某个元素是否可见并且是可用的状态, 找到返回True
wb2=WebDriverWait(wb,10,1).until(invisibility_of_element_located(("id","su")))
#invisibility_of_element_located("id","su")判断某个元素不存在或者不可见,元素不存在返回True
wb3=WebDriverWait(wb,10,1).until(text_to_be_present_in_element_value(("id","su"),"百度一下"))
#text_to_be_present_in_element_value(("id","su"),"百度一下") 判断某个表单元素的value属性是否包含了预期的字符串
wb4=WebDriverWait(wb,10,1).until(title_is("百度一下"))
#title_is("百度一下") 判断当前页面的标题是否完全等于(==)预期字符串 相等返回True
wb5=WebDriverWait(wb,10,1).until(title_contains("百度"))
#title_contains("百度") 判断当前页面的标题是否包含预期字符串 包含指定字符串返回True
wb6=WebDriverWait(wb,10,1).until(element_to_be_selected("百度"))
#element_to_be_selected("百度") 判断元素是否被选中,一般用于下拉框中