元素等待之---隐式等待

元素等待之---隐式等待

from selenium import webdriver
#导入找不到元素抛出异常说所需要的类
from selenium.common.exceptions import NoSuchElementException
from time import sleep,ctime

driver=webdriver.Firefox()
driver.get("http://www.baidu.com")
sleep(2)
#针对的全局的隐式等待
driver.implicitly_wait(5) #隐式等待时间设定 5秒

#检测搜索框是否存在
try:
	print(ctime())
	driver.find_element_by_css_selector("#kw").send_keys("Python")
	driver. find_element_by_css_selector("#su").click
except NoSuchElementException as msg:
	print(msg)
finally:
	print(ctime())

sleep(3)
driver.quit()
posted @ 2022-11-08 16:49  哈哈妞儿  阅读(9)  评论(0编辑  收藏  举报