如何解决如何使用特定配置文件加载Firefox?
我正在尝试使用Selenium和Firefox的默认配置文件打开Firefox,但根本无法打开。没有例外。 Firefox只是无法打开。这是我正在使用的代码:
IWebDriver CreateFirefoxDriver()
{
var service = FirefoxDriverService.CreateDefaultService();
var options = new FirefoxOptions();
var profile = new FirefoxProfile();
service.FirefoxBinaryPath = BrowserPaths.BrowserPaths.Firefox;
options.Profile = GetProfileDriver();
var driver = new FirefoxDriver(service,options,TimeSpan.FromSeconds(180));
driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(120);
driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(80);
return driver;
}
FirefoxProfile GetProfileDriver()
{
var path = GetFirefoxDefaultProfilePath();
//const string path = @"C:\Users\xxxx\AppData\Roaming\Mozilla\Firefox\Profiles\y7zjc15n.default-1559265775788";
var profile = new FirefoxProfile(path);
profile.AcceptUntrustedCertificates = true;
return profile;
}
string GetFirefoxDefaultProfilePath()
{
var profileRootPath = Environment.ExpandEnvironmentVariables("%APPDATA%") + @"\Mozilla\Firefox\Profiles";
var pathsToProfiles = Directory.GetDirectories(profileRootPath,"*.default",SearchOption.TopDirectoryOnly);
return pathsToProfiles.First();
}
然后致电:
driver = CreateFirefoxDriver();
driver.Navigate().GoToUrl("https://google.com");
没有打开任何东西。如果我在行options.Profile = GetProfileDriver()
上添加注释,则它会打开。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。