selenium firefox驱动_Python3+selenium配置常见报错解决方案
第一個報錯問題
'geckodriver' executable needs to be in PATH
1.1如果啟動瀏覽器過程中報如下錯誤:
Traceback?(most?recent?call?last):File?"",?line?1,?in?<module>
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.
1.2這個是因為最新的selenium3.0啟動firefox需要geckodriver.exe這個驅動文件。
1.3下載之后,配置到環境變量path下(可以直接放python根目錄)
第二個報錯問題
Expected browser binary location, but unable to find binary in default location
1.1如果啟動瀏覽器過程中報如下錯誤:
Traceback?(most?recent?call?last):File?"",?line?1,?in?<module>
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.
1.2這個是因為firefox.exe這個文件也需要配置到環境變量path下
1.3這個路徑就是安裝完firefox后,找到firefox.exe這個文件的地址,加到path下
第三個報錯問題
Unsupported Marionette protocol version 2, required 3
1.1如果啟動瀏覽器過程中出現如下錯誤:
Traceback?(most?recent?call?last):File?"",?line?1,?in?<module>
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
1.2這個錯誤原因是firefox版本過低了,最新的selenium3.0版本支持firefox47以上的版本,升級版本就可以了
第四個報錯問題
WebDriverException: Message: newSession
1.1Traceback (most recent call last):
File?“D:\test\python3\lib\site-packages\selenium\webdriver\firefox\\webdriver.py”,?line?170,?in?initkeep_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
1.2下載最新的geckodriver.exe 然后把它放到python的安裝目錄下
本文版權歸作者心安-lucky所有,歡迎轉載,但未經作者同意必須保留此段聲明,否則保留追究法律責任的權利。
專注當下 用心生活微信號:gml02030107喜歡就長按圖片掃碼關注吧作者@心安-lucky
編輯@心安-lucky
圖片@心安-lucky
總結
以上是生活随笔為你收集整理的selenium firefox驱动_Python3+selenium配置常见报错解决方案的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 五、Vue模块化开发学习笔记——Java
- 下一篇: long类型python_Python类