#导入模块
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
#启动火狐浏览器
driver = webdriver.Firefox()
#打开url
driver.get("http://www.python.org")
#添加断言
assert "Python" in driver.title
#开始定位
elem = driver.find_element_by_name("q")
#清除输入框数据
elem.clear()
#输入数据
elem.send_keys("pycon")
#模拟点击回车按钮
elem.send_keys(Keys.RETURN)
#添加断言验证
assert "No results found." not in driver.page_source
#关闭浏览器驱动
driver.close()
时间: 2024-10-24 22:52:36