Reputation: 539
I'm on selenium 2.53.0 (I don't want to update to 3.0 because I need to work on Firefox and Selenium did not implement actions for FF).
My problem is: I try to open FF in private mode (I don't want to keep the cache because I ran a lot of FF instances)
For that, I use a FF profile and I have a certificate, so I accept it.
My code is :
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();
I tried "browser.private.browsing.autostart"
and "browser.privatebrowsing.autostart"
because when I did about:config in firefox, i found this two.
I did not received any error, firefox run my test but not in private. Do you have any idea? I found this post but it haven't have answer.
Upvotes: 1
Views: 5718
Reputation: 3258
FirefoxOptions opts = new FirefoxOptions();
opts.addArguments("-private");
FirefoxDrive f = new FirefoxDriver(opts);
working currently with FF v54 and selenium 3.4.0
Upvotes: 6
Reputation: 1861
On your code sample above you are trying twice to set the profile. Try removing one of the arguments? AS long as
ffProfile.setPreference("browser.privatebrowsing.autostart", true);
is not working for you, there is an alternative workaround solution; so you can work until you figure this out.
Find any element at the page you are visiting where you want the private window to be opened. For example:
Driver.FindElement(By.ByXpath(//div[@id="loginButton"])).sendKeys(Keys.chord(Keys.CONTROL, Keys.SHIFT, "P"));
And then send a Ctrl+Shift+p to it..Then you can use the new private window for your test. Perhaps not the best solution but, this will work 100%, just tested on my machine, please comment below if you have trouble getting this right.
Best of luck!
Upvotes: 4