教你解決Python3+selenium配置常見報錯
這篇文章主要介紹了Python3+selenium配置常見報錯解決方案,文中透過示例程式碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下 |
第一個坑:'geckodriver' executable needs to be in PATH
1.如果啟動瀏覽器過程中報如下錯誤
Traceback (most recent call last): File "", line 1, inFile "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, inFile "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, inFile "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以上的版本,升級版本就可以了
第四坑:WebDriverException: Message: newSession
1.Traceback (most recent call last):
File “D:\test\python3\lib\site-packages\selenium\webdriver\firefox\\webdriver.py”, line 170, in init keep_alive=True) File “D:\test\python3\lib\site-packages\selenium\webdriver\firefox\\webdriver.py”, line 156, in init self.start_session(capabilities, browser_profile) File “D:\test\python3\lib\site-packages\selenium\webdriver\firefox\\webdriver.py”, line 245, in start_session response = self.execute(Command.NEW_SESSION, parameters) File “D:\test\python3\lib\site-packages\selenium\webdriver\firefox\\webdriver.py”, line 314, in execute self.error_handler.check_response(response) File “D:\test\python3\lib\site-packages\selenium\webdriver\firefox\\errorhandler.py”, line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: newSession
2.下載最新的geckodriver.exe 然後把它放到python的安裝目錄下
以上就是本文的全部內容,希望對大家的學習有所幫助。
原文地址:
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31559985/viewspace-2718852/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- keepalived 1.3.5常見配置以及常見問題解決
- 【彙總】Python語言常見報錯及解決方案!Python
- Hadoop常見錯誤及解決方案Hadoop
- TypeScript常見報錯TypeScript
- pip常見報錯
- RabbitMQ—常見報錯MQ
- PHP編譯安裝時常見錯誤解決辦法,php編譯常見錯誤PHP編譯
- 常見BUG解決
- JavaScript 除錯常見報錯以及原因JavaScript除錯
- PbootCMS網站常見報錯boot網站
- Elasticsearch常見的5個錯誤及解決策略Elasticsearch
- 爬蟲常見錯誤程式碼及解決措施爬蟲
- RHCE常見的報錯問題
- Ubuntu下Linux配置核心各種常見錯誤和解決辦法UbuntuLinux
- SSL證書7大常見錯誤及解決方法!
- 海外常見的http錯誤程式碼原因與解決HTTP
- 中科三方——SSL常見錯誤及解決方法
- CrashSight 接入上報常見問題及解決方案
- 解決帝國CMS安裝出錯和常見問題
- SSL證書七大常見錯誤及解決方法
- DKhadoop安裝配置步驟教程與常見問題解決Hadoop
- As常見問題解決方法
- git常見問題解決Git
- CentOS7系統安裝虛擬環境,安裝及相關報錯問題解決方案、配置、問題解決、常見相關命令CentOS
- PhpCms安裝報錯怎麼辦?PHPCMS安裝使用常見問題解決辦法PHP
- 開發微信小程式之HTTPS報錯常見問題彙總及解決方法微信小程式HTTP
- 前端JavaScript 常見的報錯及異常捕獲前端JavaScript
- CentOS 常見異常及解決辦法CentOS
- vscode與chrome除錯配置與常見問題VSCodeChrome除錯
- MySQL 主從複製,常見的binlog錯誤及解決方法MySql
- 騰訊藍鯨自動化運維平臺簡介部署及常見報錯解決運維
- docker常見配置Docker
- Nginx常見配置Nginx
- 安卓so包常見報錯問題安卓
- LightDB Canopy 常見報錯問題分析(一)
- Git常見問題及解決Git
- python logging常見的解決方案Python
- mybatis報錯解決MyBatis