IE11,Chrome65,Firefox58 的webdriver驱动下载,调用浏览器打开网址

1、环境及需求

1.1环境html

Windows10 + Python 3.6.4 + selenium 3.141java

 

1.2需求python

工做须要实现一个网页自动登陆的操做,决定使用selenium+python实现git

 

selenium 是一个web的自动化测试工具,主流通常配合java或者python使用,github

我这里使用的是python,可支持的浏览器基本包括全部主流浏览器IE、Mozilla Firefox、Google Chrome。web

 

2、环境配置

2.1 python安装chrome

直接在官网下载python安装包,api

https://www.python.org/ftp/python/3.7.3/python-3.7.3-amd64.exe浏览器

安装后查看版本工具

> python
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 10:22:32) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

2.2 selenium安装

CMD命令行安装模块selenium 便可,命令以下:

pip install selenium

安装后查看版本

> pip show selenium
libpng warning: iCCP: known incorrect sRGB profile
Name: selenium
Version: 3.141.0
Summary: Python bindings for Selenium
Home-page: https://github.com/SeleniumHQ/selenium/
Author: UNKNOWN
Author-email: UNKNOWN
License: Apache 2.0
Location: c:\programdata\miniconda3\lib\site-packages
Requires: urllib3
Required-by:

 

3、webdriver驱动下载网址及调用代码

 

使用方法, 放到python文件目录下. 示例:C:/Users/Administrator/Desktop 目录下。

ps:假如运行报错, 八成是版本不对,下载的版本宁肯高不可低

 

3.1 IE11的Webdriver下载:

https://dl.pconline.com.cn/download/771640-1.html

备用地址

https://www.microsoft.com/en-us/download/confirmation.aspx?id=44069

IE导入代码:

1 from selenium import webdriver
2 
3 wb = webdriver.Ie()
4 wb.get("https://www.baidu.com/")

 

3.2 Chrome65.0.3325.146的webdriver驱动下载

http://chromedriver.storage.googleapis.com/index.html

Chrome导入代码:

1 from selenium import webdriver
2 
3 wb = webdriver.Chrome()
4 wb.get('https://www.baidu.com/')

 

3.3 Firefox58的webdriver驱动下载

https://github.com/mozilla/geckodriver/releases

Firefox导入代码:

from selenium import webdriver

wb = webdriver.Firefox()
wb.maximize_window()
wb.get("https://www.baidu.com/")
相关文章
相关标签/搜索