You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Selenium Firefox配置文件无法加载的问题求助

Selenium Firefox配置文件无法加载的问题求助

我的环境版本信息如下:

.\geckodriver --version = geckodriver 0.35.0 (9f0a0036bea4 2024-08-03 07:11 +0000)

    Name: selenium
    Version: 4.27.1
    Summary: Official Python bindings for Selenium WebDriver
    Home-page: https://www.selenium.dev
    Author:
    Author-email:
    License: Apache 2.0
    Location: C:\Users\Whatisit\PycharmProjects\api_database\.venv\Lib\site-packages
    Requires: cert

我已经尝试了多种方法来配置Firefox加载指定配置文件,但始终无法成功,具体尝试的操作如下:

  1. 尝试了多种Options的调用写法:
from selenium.webdriver.firefox import webdriver
from selenium.webdriver.firefox.options import Options

options = webdriver.Options()
options = Options()
from selenium.webdriver.firefox import webdriver
from selenium.webdriver.firefox.options import Options

options = webdriver.Options()
options = Options()
  1. 针对配置文件路径(不管是硬编码还是动态获取的路径),试了三种设置方式:
  • 版本1:
options.set_profile(profile_path)
  • 版本2:
options.add_argument("-profile")
options.add_argument(profile_path)
  • 版本3:
options.set_preference('profile', profile_path)
  1. 同时搭配设置Firefox二进制文件路径:
options.binary_location = "geckodriver的路径"
  1. 还试过通过Service传递配置的方式:
from selenium import webdriver
from selenium.webdriver.firefox import service

service_args=[]
service_args.append("--profile")
service_args.append("/path/to/profile")
service = service.Service(service_args=service_args)
options = webdriver.FirefoxOptions()
driver = webdriver.Firefox(service=service, options=options)
from selenium import webdriver
from selenium.webdriver.firefox import service
  1. 也尝试过直接在Service或FirefoxService中指定geckodriver的路径。

另外我还参考了Selenium官方的测试用例来调整代码,测试用例里的配置文件相关逻辑是能正常运行的,但我的代码就是加载不了指定的配置文件。

我查看了Service的运行日志,大部分内容都正常,只出现过一条错误提示:

services.settings: ignoring preference override of remote settings server

现在实在找不到解决方向了,有没有人能帮忙排查一下问题?

备注:内容来源于stack exchange,提问作者unboundcoding

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 17:34:35