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加载指定配置文件,但始终无法成功,具体尝试的操作如下:
- 尝试了多种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:
options.set_profile(profile_path)
- 版本2:
options.add_argument("-profile") options.add_argument(profile_path)
- 版本3:
options.set_preference('profile', profile_path)
- 同时搭配设置Firefox二进制文件路径:
options.binary_location = "geckodriver的路径"
- 还试过通过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
- 也尝试过直接在Service或FirefoxService中指定geckodriver的路径。
另外我还参考了Selenium官方的测试用例来调整代码,测试用例里的配置文件相关逻辑是能正常运行的,但我的代码就是加载不了指定的配置文件。
我查看了Service的运行日志,大部分内容都正常,只出现过一条错误提示:
services.settings: ignoring preference override of remote settings server
现在实在找不到解决方向了,有没有人能帮忙排查一下问题?
备注:内容来源于stack exchange,提问作者unboundcoding
相关产品推荐
相关产品推荐

