我在使用 selenium 2.53.0(我不想更新到 3.0,因为我需要在 Firefox 上工作,而 Selenium 没有为 FF 实现操作)。
我的问题是:我尝试以私有(private)模式打开 FF(我不想保留缓存,因为我运行了很多 FF 实例)
为此,我使用了 FF 配置文件并且我有证书,所以我接受它。
我的代码是:
FirefoxDriverManager.getInstance().setup();
capabilities.setBrowserName("firefox");
capabilities.setVersion("46");
ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffProfile = profile.getProfile("default");
ffProfile.setPreference("browser.private.browsing.autostart", true);
ffProfile.setPreference("browser.privatebrowsing.autostart", true);
//accept the certificate
ffProfile.setAcceptUntrustedCertificates(true);
ffProfile.setAssumeUntrustedCertificateIssuer(false);
capabilities.setCapability(FirefoxDriver.PROFILE, ffProfile);
WebDriver webDriver = new FirefoxDriver();
我尝试了 "browser.private.browsing.autostart"
和 "browser.privatebrowsing.autostart"
因为当我在 firefox 中执行 about:config 时,我发现了这两个.
我没有收到任何错误,firefox 运行我的测试但不是私下。你有什么主意吗? 我找到了这个 post但它没有答案。
最佳答案
FirefoxOptions opts = new FirefoxOptions();
opts.addArguments("-private");
FirefoxDrive f = new FirefoxDriver(opts);
目前使用 FF v54 和 selenium 3.4.0
关于java - 如何在 Selenium 2.53.1 中将我的 Firefox 浏览器设置为私有(private)模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41587461/