我有一些配置文件想在 Firefox 中使用。 我尝试为配置文件设置自定义文件夹,但 Firefox 无法加载该配置文件。 我现在的代码:
FirefoxOptions options = new FirefoxOptions();
options.AddArguments(@"user-data-dir=C:\SomeFolder\firefox" + @"\" + profilename + @"\");
IWebDriver driver = new FirefoxDriver(options);
您需要在选项类上设置 Profile 属性,例如
options.Profile = new FirefoxProfile("PATH_TO_PROFILE");
可悲的是,这似乎存在一个很多人都遇到过的问题。幸运的是,有一个出色的答案可以让这个真正发挥作用,链接如下。我建议按照答案加载您的自定义配置文件。
对于任何需要 Python 帮助的人,我花了一段时间,但就在这里
profile = "/home/{user}/.mozilla/firefox/{foldername}.default-release"
optns.add_argument(f"--profile={profile}")
dvr = webdriver.Firefox(options=optns)
P.S 需要先关闭 Firefox 的任何实例