1 框架介绍
Selenium自动化测试框架是以浏览器为基础,在浏览器驱动的作用下通过代码对浏览器就行操控,比如搜索 刷新 点击等。
更多可参考
http://www.51testing.com/zhuanti/selenium.html
2 框架使用前准备
需要安装浏览器驱动,选择和自己浏览器相对应驱动名称和版本即可,可到下面连接进行下载
http://chromedriver.storage.googleapis.com/index.html
http://chromedriver.storage.googleapis.com/index.html
驱动安装,也比较简单配置环境即可
https://www.cnblogs.com/technologylife/p/5829944.html
3 浏览器简单操作,使用浏览器访问必应并搜索北京时间
import time
from selenium import webdriver
option = webdriver.ChromeOptions() #浏览器设置
#option.add_argument('--headless')#不打开浏览器
browser = webdriver.Chrome(options = option)
browser.get("http://www.biying.com") #搜索引擎
browser.find_element_by_id('sb_form_q').send_keys('北京时间') #找到输入框并输入关键字
browser.find_element_by_id('sb_form_go').click()
broswer.quite()#退出浏览器
4 效果图,会有浏览器被驱动控制的提示