How to stop Selenium from creating temporary Firefox Profiles using Web Driver?

You can control how the Firefox driver chooses the profile. Set the webdriver.firefox.profile property to the name of the profile you want to use. Most folks think this is a bad idea, because you'll inherit all the cookies, cache contents, etc. of the previous uses of the profile, but it's allowed if you really want to do it.

For example:

System.setProperty("webdriver.firefox.profile", "MySeleniumProfile");
WebDriver driver = new FirefoxDriver(...);

UPDATE - From Ranhiru

How I handled it for Java

FirefoxProfile profile = new FirefoxProfile(new File("D:\\Selenium Profile"));                  
WebDriver driver = new FirefoxDriver(profile);

Then I changed settings in Firefox to clear all cookies and cache when exiting. Look here on how to do it.


Be sure you call

driver.quit();

instead of

driver.close();

close() will not delete temporary files


The answer was actually pretty easy after I went through this question where I found the documentation. I found the FirefoxProfile class and the constructor took the path to the Firefox Profile.

WebDriver driver = null;
FirefoxProfile profile = new FirefoxProfile(new File("C:\\Users\\Ranhiru\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\qp1nizdo.Selenium"));
driver = new FirefoxDriver(profile);

I created a new profile by running "Firefox.exe" with the -p flag.

Firefox.exe -p

Installed the extensions I needed to this profile and I was good to go! :)

Update

It does not matter whether you assign a profile or not, the temporary profile in the temp folder is created nevertheless. By creating and assigning a profile you get the chance to use firebug/xpather/your favorite extension when testing.


You can load the FirefoxWebDriver with the desired plugins by calling addExtension(File) method in FirefoxProfile class.

Example:

try {
    File firebug = new File("C:\\FFPlugins\\firebug-1.7.3.xpi");
    File xpathChecker = new File("C:\\FFPlugins\\xpath_checker-0.4.4-fx.xpi");
    profile.addExtension(firebug);
    profile.setPreference("extensions.firebug.currentVersion", "1.7.3");
    profile.addExtension(xpathChecker);
    profile.setPreference("extensions.xpath_checker.currentVersion", "0.4.4");
} catch(IOException e) {
    e.printStackTrace();
}
driver = new FirefoxDriver(profile);

I have create a custom profile by running the command:

firefox -profileManager 

(then adding any exceptions etc I require - as due to selenium opening clean profile/instance each time the exceptions are lost)

I was then directly creating my Firefox with this profile using the following:

private static String profilePath = "C:\\fitnesse\\Selenesse\\FFProfiles";
private static FirefoxProfile ffprofile = new FirefoxProfile(profilePath); 
private static IWebDriver driver = new FirefoxDriver(ffprofile);