robot selenium+python 对火狐浏览器进行网页自动化测试 报错历程
robotfremaker selenium+python 使用
我的安裝版本:python2.7 查看版本 cmd命令下輸入python
用pip安裝了selenum 3.11.0 查看版本 cmd命令下輸入pip show selenium
火狐版本38.8.0
在使用Open Browser關鍵字打開瀏覽器時,報錯信息如下:
20180416 15:06:49.348 : INFO : Cannot capture screenshot because no browser is open.
WebDriverException: Message: ‘geckodriver’ executable needs to be in PATH.
本著用最新版selenium 3
網上搜了各種解決辦法,
1.單獨下載火狐插件geckodriver,解壓到火狐安裝根路徑,(下載地址:https://github.com/mozilla/geckodriver/releases 根據自己的電腦下載的最新版64位的v0.20.1 )
2.然后將該路徑添加到path環境變量下。再次運行,報了一個新的錯誤:“selenium.common.exceptions.WebDriverException: Message: Unable to find a matching set of capabilities”
3.繼續各種問度娘,原因是geckodriver版本與selenum版本不兼容,沒有特別明確的版本對應說明,于是從0.20.1依次降低版本,嘗試,最終使用deckdriverV0.15版本成功
4.此時運行又報了一個新的錯誤,:“selenium.common.exceptions.WebDriverException: Message: Unsupported Marionette protocol version 2, required 3;
5.繼續往上查原因,說是firefox版本太低了,需要升級到最新版,我當前是38.8.0. 網上百度,升級到40.0 或41.0 可以成功
6.我升級到41.0,運行后,發現只打開了瀏覽器,而沒有打開網址,繼續報錯。錯誤提示:Cannot capture screenshot because no browser is open.WebDriverException: Message: Not a Numbe
7.啊啊啊,我的報錯之路,卡在這里了,嘗試了依次升級firefox到47.0 依然報錯Not a Number
耐心嘗試,繼續升級。火狐升級到59.0
大神解釋:這種問題一般為版本問題:Selenium版本為3,或者火狐版本太高,一般Selenium2支持46以下的
8.selenium與火狐版本不兼容,嘗試升級selenium的jar包,或兼容firefox低版本
傳說在selenium下載頁面 http://www.seleniumhq.org/download/ (需FQ) 各個版本的changelog中,會記錄支持的firefox版本。 en。。。。。。這些個官網我永遠打開都是無法訪問此網站以告終。。
方法二,降低selenium版本。
卸載selenium版本:
cmd下輸入:pip uninstall selenium
安裝: pip install selenium x.xx.x(對應selenium版本) 一般Python 2.x 對應 selenium 2.x python 3.x 對應 selenium 3.xx
如果安裝失敗,報 錯:Cannot fetch index base URL https://pypi.python.org/simple/ Could not find any downloads that satisfy the requirement selenium
可以下載安裝 下載地址:https://pypi.python.org/pypi/selenium/2.42.1
進入下載文件存放地址 cmd cd 進入 python setup.py install pip show selenium查看安裝版本
網友給出的selenium java對應 firefox 版本號,我就沒有一一嘗試,
2.25.0 -> 18
2.30.0 -> 19
2.31.0 -> 20
2.42.2 -> 29
2.44.0 -> 33 (不支持31)
2.53.0 -> 43,46(不支持47)
2.41.0 -> 26(綠色版本)
2.44 -> 32.0-35.0
2.53.0-2.53.6 -> 40.0.3
親測
2.53.2 ->38.8-45.5.1
3.11.0 -> 59.0
elenium-java-2.42.2版本和firefox 29.0.1版本兼容,如果升級到firefox 30+,則瀏覽器啟動失敗。可能是selenium還未同步升級,后面估計可以正常支持。
若selenium的版本和firefox不兼容,需要升級selenium的jar包,或者是升級firefox。
因為Selenium3不支持向前支持火狐瀏覽器了,40以后版本的火狐,運行會出現問題。
附:
各firefox版本下載地址
http://ftp.mozilla.org/pub/firefox/releases/
各selenium版本下載地址:
https://pypi.python.org/pypi/selenium/
火狐插件geckodriver下載地址:
https://github.com/mozilla/geckodriver/releases
最終以selenium-python-2.53.2版本和firefox 38.8.0版本兼容
以及selenium-python-3.11.0 版本和firefox 59.0 版本兼容
成功。。。至此,我把歷時一天的改錯歷程分享出來,供大家參考。邀請大神指出其中錯誤之處。
總結
以上是生活随笔為你收集整理的robot selenium+python 对火狐浏览器进行网页自动化测试 报错历程的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 漂亮的网页动态飘花灯笼特效代码
- 下一篇: 清洗完相机拍照测试年龄的软件,算年龄的照