我一直在搜索很多并找到了很多答案,但没有一个有效。我想以私人模式启动Firefox Webdriver。
我安装了Firefox 54,gecko驱动程序v0.18。 Selenium v3.4.0
我使用以下代码:
FirefoxProfile profile = new FirefoxProfile();
profile.EnableNativeEvents = true;
profile.AcceptUntrustedCertificates = true;
profile.AssumeUntrustedCertificateIssuer = true;
profile.SetPreference("browser.privatebrowsing.autostart", true);
profile.SetPreference("browser.privatebrowsing.dont_prompt_on_enter", true);
//profile.SetPreference("browser.startup.homepage", ConfigurationManager.AppSettings["StartURL"]);
FirefoxOptions options = new FirefoxOptions();
options.Profile = profile;
//options.AddArgument("--private");
FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(DRIVER_PATH);
webDriver = new FirefoxDriver(service, options, TimeSpan.FromMilliseconds(15000));
var screenWidth = Screen.PrimaryScreen.Bounds.Width;
var screenHeight = Screen.PrimaryScreen.Bounds.Height;
webDriver.Manage().Window.Size = new System.Drawing.Size(screenWidth, screenHeight);
webDriver.Navigate().GoToUrl(ConfigurationManager.AppSettings["StartURL"]);
//from firefox 55 can maximize again. Wait for update.
//webDriver.Manage().Window.Maximize();
我还注意到,当我在测试期间调试并按下CTRL + SHIFT + P时,会打开一个新的“私人”窗口但我看不到私人眼镜图标。怎么了?这是一个错误吗?