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/")
相關文章
相關標籤/搜索