前置条件:
1.Windows键+R打开命令提示符
2.输入命令pip list
3.查看selenium是否配置,查看版本是不是3.14.1
4.如果没有,输入pip insert selenium==3.14.1
5.提前安装好谷歌,火狐,edge游览器
火狐游览器环境搭建
1.打开网页链接https://github.com/mozilla/geckodriver/releases
2.找到Windows版本,下载对应的驱动
3.下载之后解压把 geckodriver.exe 的驱动放到python的安装目录下
4.编写测试脚本如下,游览器启动打开表示成功
from selenium import webdriver
dri = webdriver.Firefox()
dri.get('http://www.baidu.com')
谷歌
1.打开谷歌浏览器,在设置里面查看谷歌浏览器的版本
2.打开https://chromedriver.storage.googleapis.com/index.html 链接,找到合适的版本号的驱动,进入下载windows的驱动
3.下载的驱动压缩包解压,然后把 chromedriver.exe 的文件放在python的安装目录下
4.编写脚本进行测试,如下:浏览器启动之后打开百度的页面表示成功
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('http://www.baidu.com')
Edge
1.打开https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/链接
2.查看Edge浏览器的版本,下载合适的驱动
3.解压驱动之后能看到一个名为msedgedriver.exe的文件,重命名为:MicrosoftWebDriver.exe文件
4.把重命名之后的文件放入python的安装目录
5.编写测试脚本如下,游览器启动表示成功
from selenium import webdriver
driver = webdriver.Edge()
driver.get('http://www.baidu.com')