Python3+selenium配置常见报错解决方案
第一个坑:'geckodriver' executable needs to be in path
1.如果启动浏览器过程中报如下错误
traceback (most recent call last):
file "<stdin>", 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.
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 "<stdin>", 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.
2.这个是因为firefox.exe这个文件也需要配置到环境变量path下。
3.这个路径就是安装完firefox后,找到firefox.exe这个文件的地址,加到path下。
第三坑:unsupported marionette protocol version 2, required 3
1.如果启动浏览器过程中出现如下错误
traceback (most recent call last):
file "<stdin>", 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_responseraise 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的安装目录下
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
推荐阅读
-
Xcode8下iOS10常见报错闪退,字体适配和编译不过的问题及解决方案
-
Xcode8下iOS10常见报错闪退,字体适配和编译不过的问题及解决方案
-
Mycat分布式数据库架构解决方案--配置defaultAccount属性报错解决方案
-
IIS7 网站发布常见报错问题解决方案汇总
-
C语言开发中常见报错的解决方案
-
Sublime Text4 配置 Python3 环境、代码提示、编译报错的解决方案
-
Python3+selenium配置常见报错解决方案
-
SQL Server2008安装报错,解决方案(创建 system.diagnostics 的配置节处理程序时出错)
-
Mycat分布式数据库架构解决方案--配置defaultAccount属性报错解决方案
-
linux 下配置PHP mysql时,在启动/usr/local/mysql/bin/mysqld_safe &报错Operating system error number 13 in a file operation.解决方案