selenium自動化測試軟件的安裝(python+selenium3.0+firefox54)

selenium2.X和selenium3.x的使用環境佈局是不一樣的,selenium只支持單個特定的Firefox版本,本篇使用的python+selenium3.0+firefox54的安裝,我已經測驗過了,是可以使用的,如果用selenium2.0,最好使用低版本的Firefox,如40,谷歌瀏覽器也支持selenium自動化測試,只不是需要下載相對應的jar包;有興趣的可以看看
selenium版本下載鏈接:
https://wenku.baidu.com/view/71e4eb3a767f5acfa0c7cd62.html
http://gitbook.net/selenium/selenium_environment_setup.html
https://blog.csdn.net/golearn/article/details/50366939

各firefox版本下載地址
http://ftp.mozilla.org/pub/firefox/releases/

各selenium jar包下載地址
http://selenium-release.storage.googleapis.com/index.html
本文以python+selenium3.0+firefox54的安裝爲例
環境準備:
• 下載並安裝Java http://www.oracle.com/technetwork/java/javase/downloads/index.htmll
• 下載安裝Firefox(<=54.0版本)
http://ftp.mozilla.org/pub/mozilla.org//firefox/releases/
• 配置Firebug和FirePath
• 配置Selenium的webdriver
• 下載Python
一、Java安裝

  1. 下載安裝,next根據習慣選擇安裝目錄

  2. 安裝成功後,檢查時候安裝成功,如果失敗會報unknown command”的錯誤
    Cmd
    Java /java -version(檢查java版本)
    在這裏插入圖片描述
    二、Selenium IDE ,Firebug,firepath安裝配置
    Selenium IDE 下載及安裝
    直接用Firefox打開https://addons.mozilla.org/en-US/firefox/addon/selenium-ide/,點擊”Add to Firefox”就可以了
    Firebug,firepath安裝配置

  3. 因爲Firebug在新版Firefox中被淘汰,所以需要下載Firefox54.0之前的版本,安裝Firefox成功後,添加配置Firebug,firepath

  4. 找到的網址:https://addons.mozilla.org/en-US/firefox/addon/firebug/ 並下載插件,+Add to firefox;安裝
    在這裏插入圖片描述

  5. 安裝完成後,可以在啓動插件導航欄中看到
    在這裏插入圖片描述

  6. Firepath一個插件,它的工作原理中的螢火蟲幫助用戶抓住一個元素“Xpath”。導航到“https://addons.mozilla.org/en-US/firefox/addon/firepath/”安裝Firepath,
    在這裏插入圖片描述

安裝成功後,可以看到
在這裏插入圖片描述
三、Python3.x安裝
1.安裝python ,next
2.安裝好之後,看下這個目錄D:\python\Scripts,有沒pip.exe和easy_install.exe(一般都有,沒有的話得重新安裝一次)
3.檢查是否安裝成功:
cmd
Python
在這裏插入圖片描述
(如果失敗)將D:\python和D:\python\Scripts,添加到環境變量path下
四、安裝selenium3.0
1、檢查pip工具
打開cmd,輸入:pip,出現如下圖界面,說明pip環境OK.
pip
在這裏插入圖片描述
要是出現異常提示:Did not provide a command,就看這篇解決:

http://www.cnblogs.com/yoyoketang/p/6111644.html
2、安裝selenium3.0
(1).cmd輸入:pip install selenium

pip install selenium
(2).首次安裝要看到100%完成,中途失敗就重新多輸入幾次安裝。

Python安裝目錄的Scripts下執行
在這裏插入圖片描述
3、檢查selenium環境
1.在cmd輸入如下指令檢查環境

python
from selenium import webdriver
driver=webdriver.Firefox()
driver.get(“https://www.baidu.com”)
2.能看到瀏覽器正常啓動,說明環境OK
**

注:可能會出現的異常信息及解決方法

’geckodriver’ executable needs to be in PATH
1.如果啓動瀏覽器過程中報如下錯誤
Traceback (most recent call last):
File “”, line 1, in
File “D:\test\python3\lib\site-packages\selenium\webdriver\firefox\webdriver.py”, line 145, in init
self.service.start()
File “D:\test\python3\lib\site-packages\selenium\webdriver\common\service.py”, line 81, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: ‘geckodriver’ executable needs to be in PATH.
2.這個是因爲最新的selenium3.0啓動firefox需要geckodriver.exe這個驅動文件。
3.下載之後,配置到環境變量path下(可以直接放python根目錄)

Expected browser binary location, but unable to find binary in default location
1.如果啓動瀏覽器過程中報如下錯誤
Traceback (most recent call last):
File “”, line 1, in
File “D:\test\python3\lib\site-packages\selenium\webdriver\firefox\webdriver.py”, line 155, in init
keep_alive=True)
File “D:\test\python3\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 92, in init
self.start_session(desired_capabilities, browser_profile)
File “D:\test\python3\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File “D:\test\python3\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 238, in execute
self.error_handler.check_response(response)
File “D:\test\python3\lib\site-packages\selenium\webdriver\remote\errorhandler.py”, line 193, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Expected browser binary location, but unable to find binary in default location, no ‘moz:firefoxOptions.binary’ capability provided, and no binary flag set on the command line
2.這個是因爲firefox.exe這個文件也需要配置到環境變量path下
3.這個路徑就是安裝完firefox後,找到firefox.exe這個文件的地址,加到path下
在這裏插入圖片描述

Unsupported Marionette protocol version 2, required 3
1.如果啓動瀏覽器過程中出現如下錯誤
Traceback (most recent call last):
File “”, line 1, in
File “D:\test\python3\lib\site-packages\selenium\webdriver\firefox\webdriver.py”, line 155, in init
keep_alive=True)
File “D:\test\python3\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 92, in init
self.start_session(desired_capabilities, browser_profile)
File “D:\test\python3\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File “D:\test\python3\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 238, in execute
self.error_handler.check_response(response)
File “D:\test\python3\lib\site-packages\selenium\webdriver\remote\errorhandler.py”, line 193, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Unsupported Marionette protocol version 2, required 3
2.這個錯誤原因是firefox版本過低了,最新的selenium3.0版本支持firefox47以上的版本,升級版本就可以了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章