预期的浏览器二进制位置,但无法在默认位置找到二进制,不提供'moz:firefoxOptions.binary'功能 [英] Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided
问题描述
我正试图重新使用python webdriver.我在这里有代码
I am trying to get back into using python webdriver. I have here the code
from selenium import webdriver
driver = webdriver.Firefox(executable_path=r'C:\Users\Cody\Downloads\geckodriver.exe')
driver.get('http://inventwithpython.com')
这导致:
C:\Users\Cody\Projects>python accounting.py
Traceback (most recent call last):
File "accounting.py", line 4, in <module>
driver = webdriver.Firefox(executable_path=r'C:\Users\Cody\Downloads\geckodriver.exe')
File "C:\Users\Cody\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\firefox\webdriver.py", line 170, in __init__
RemoteWebDriver.__init__(
File "C:\Users\Cody\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\Cody\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\Cody\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\Cody\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: 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
如果我尝试:
from selenium import webdriver
driver = webdriver.Firefox(executable_path=r'C:\Users\Cody\Downloads')
driver.get('http://inventwithpython.com')
我知道
C:\Users\Cody\Projects>python accounting.py
Traceback (most recent call last):
File "C:\Users\Cody\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\common\service.py", line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2032.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.2032.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
PermissionError: [WinError 5] Access is denied
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "accounting.py", line 4, in <module>
driver = webdriver.Firefox(executable_path=r'C:\Users\Cody\Downloads')
File "C:\Users\Cody\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\firefox\webdriver.py", line 164, in __init__
self.service.start()
File "C:\Users\Cody\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\selenium\webdriver\common\service.py", line 86, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'Downloads' executable may have wrong permissions.
Geckodriver.exe位于下载文件夹中.任何帮助表示赞赏
Geckodriver.exe is sitting right there in the downloads folder. Any help appreciated
推荐答案
此错误消息...
selenium.common.exceptions.SessionNotCreatedException: 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
...表示 GeckoDriver无法找到 firefox 可执行文件尝试启动/产生新的浏览上下文时,即 Firefox浏览器会话.
...implies that the GeckoDriver was unable to locate the firefox executable while trying to initiate/spawn a new Browsing Context i.e. Firefox Browser session.
此错误的两个主要原因如下:
The two primary reasons for this error are as follows:
- 系统中未安装
- Firefox .
- Firefox 未安装在系统的默认位置.
- Firefox isn't installed within your system.
- Firefox isn't installed at the default location within your system.
可能的解决方案是:
-
如果系统中未安装 Firefox ,则需要先安装它,然后再执行测试.
If Firefox isn't installed in your system, you need to install it before executing your tests.
如果将 Firefox 安装在自定义位置,则需要通过以下方式传递 firefox 二进制文件的绝对路径: Options()
实例:
If Firefox is installed at a customized location, you need to pass the absolute path of the firefox binary as follows through an Options()
instance:
from selenium import webdriver
options = webdriver.FirefoxOptions()
options.binary_location = r"C:/location/to/Firefox/Binary/firefox.exe"
driver = webdriver.Firefox(executable_path=r'C:\Users\Cody\Downloads\geckodriver.exe', options=options)
driver.get('http://inventwithpython.com/')
您可以在以下位置找到几个相关的详细讨论:
You can find a couple of relevant detailed discussion in:
- SessionNotCreatedException:消息:预期的浏览器二进制位置,但无法在默认位置找到二进制文件,没有'moz:firefoxOptions.binary'
- InvalidArgumentException:消息:二进制不是使用GeckoDriver Firefox Selenium和Python的Firefox可执行错误
- 预期浏览器的二进制位置,但无法在默认位置找到二进制文件,没有使用GeckoDriver提供的'moz:firefoxOptions.binary'功能
这篇关于预期的浏览器二进制位置,但无法在默认位置找到二进制,不提供'moz:firefoxOptions.binary'功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!