第二十九节 selenium隐式和显式等待
1 from selenium import webdriver 2 from selenium.webdriver.chrome.options import Options 3 4 5 browers_path = r'C:\Users\Administrator\AppData\Local\360Chrome\Chrome\Application\360chrome.exe' 6 chrome_option = Options() 7 chrome_option.binary_location = browers_path 8 browers_driver = webdriver.Chrome(options=chrome_option) 9 browers_driver.get("http://www.baidu.com") 10 11 ''' 12 隐式等待 13 会等待指定时间,不管这个元素有没有刷新或者获取到 14 ''' 15 # browers_driver.implicitly_wait(20) 16 # browers_driver.find_element_by_id('12342435') 17 18 ''' 19 显式等待:如果在限定条件下去到了元素就会结束程序,否则会等到规定限定时间抛出错误 20 ''' 21 from selenium.webdriver.support.ui import WebDriverWait 22 from selenium.webdriver.support import expected_conditions as EC 23 from selenium.webdriver.common.by import By 24 # 25 elment = WebDriverWait(browers_driver,10).until( 26 EC.presence_of_element_located((By.NAME,'wd'))#只能传一个参数,因此要放进一个元组中 27 ) 28 29 print(elment)