2

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?

Shumaila
  • 41
  • 6

1 Answers1

3

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");
Guy
  • 46,488
  • 10
  • 44
  • 88
  • and about 2nd problem i am reading here http://stackoverflow.com/questions/1138953/open-firefox-window-in-selenium-with-firefox-addons-loaded , can you plz help me accourding to my given code? in that question they are using something RemoteControlConfiguration – Shumaila Jan 25 '16 at 15:41
  • @Shumaila I added solution for the second problem. – Guy Jan 25 '16 at 15:41
  • sir, what path i have to use in Binary? my profile path or something else? my profile path is C:\\Users\\Shum\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\qrxeiurf.1 – Shumaila Jan 25 '16 at 15:51
  • @Shumaila You need to use the browser path – Guy Jan 25 '16 at 15:54
  • @Shumaila I added second option – Guy Jan 25 '16 at 15:56
  • ok thanks i am trying to find what is binary path of my firefox. – Shumaila Jan 25 '16 at 15:58