如何在 windows 上使用 selenium/python 设置便携式 Firefox?

How to setup portable Firefox using selenium/python on windows?

我已经尝试使用此 python 脚本在 windows 上的便携式 Firefox 中打开 url,但我得到 SessionNotCreatedException 回溯。

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary('path\to\FirefoxPortable32.exe')
exec_path = "path\to\geckodriver32.exe"
browser = webdriver.Firefox(executable_path=exec_path, firefox_binary=binary)
browser.get('some_url')

这是回溯:

File "tst.py", line 20, in browser = webdriver.Firefox(executable_path=exec_path, firefox_binary=binary) File "C:\Program Files (x86)\Python37-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 174, in init keep_alive=True) File "C:\Program Files (x86)\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in init self.start_session(capabilities, browser_profile) File "C:\Program Files (x86)\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "C:\Program Files (x86)\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute self.error_handler.check_response(response) File "C:\Program Files (x86)\Python37-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities

我正在使用:

windows 7 (64 bit)
python 3.7
selenium 3.141
geckdriver v0.24.0 (64 bit)
FirefoxPortable 68.0.1 (64 bit)

知道如何让便携式 Firefox 工作吗?

将 Firefox 二进制文件的路径更改为 "App" 文件夹中的 firefox.exe 文件。 例如。 'path\to\FirefoxPortable\App\Firefox\firefox.exe'