Shumaila
Shumaila

Reputation: 41

Open Firefox Profile with privatebrowsing in Selenium

i have many profiles in Firefox to open in selenium, now i want to open a Firefox profile in Private Browsing Mode. How to Open Firefox Profile with privatebrowsing in Selenium? here is my code

ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffprofile = profile.getProfile("1");
ffprofile.set_preference("browser.privatebrowsing.autostart", True);
WebDriver driver = new FirefoxDriver(ffprofile);
driver.get("http://proxy.cm/");
try {Thread.sleep(13000);} catch (InterruptedException e) {e.printStackTrace();}

this line shows error

ffprofile.set_preference("browser.privatebrowsing.autostart", True); 

above line show error "True cannot be resolved to a variable".

One more problem i am facing that Selenium is not updating Firefox profiles, i mean i installed some new extention, i also changed some setting in firefox profile but Selenium always open Firefox with old settings, extensions. how can i force Selenium to open firefox profile with updated new settings and extentions?

Upvotes: 2

Views: 1224

Answers (1)

Guy
Guy

Reputation: 51009

Your syntax is not Java, but Python (I think).

ffprofile.setPreference("browser.privatebrowsing.autostart", true);

Note the difference in setPreference and true.

And for the second problem you can specify the path to the version you want

FirefoxBinary binary = new FirefoxBinary(new File("path_to_firefox"));
FirefoxProfile ffprofile = profile.getProfile("1");
ffprofile.setPreference("browser.privatebrowsing.autostart", true);
WebDriver driver = new FirefoxDriver(binary, ffprofile);

Another option is to define the path for Firefox in System property

System.setProperty("webdriver.firefox.bin", "/Applications/Firefox-2.app/Contents/MacOS/firefox-bin");

Upvotes: 3

Related Questions