How to Stop Selenium from Creating Temporary Firefox Profiles Using Web Driver

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.

Why Selenium always create temporary Firefox Profiles using Web Driver?

The main reason that the Firefox driver uses a temporary profile is to support the use case of running multiple independent simultaneous instances of Firefox. At one time, when Firefox launched, it would drop a sentinel or lock file in the profile directory, and would detect that file if the user attempted to start a new instance of Firefox, preventing them from doing so. Whether or not Firefox still exhibits this behavior, the driver still has to work with some older versions of the browser, and has to account for it. The Selenium project's solution to that issue with WebDriver, when a user wants to use a specific profile, is to copy the contents of that profile to a new directory, and launch Firefox pointing to the copy.

It sounds like Mozilla's implementation does largely the same thing. I would guess it's for the same reason - to support the multiple-instance use case.



Related Topics



Leave a reply



Submit