Selenium Firefox Profile: Setup Guide
โก Smart Summary
Firefox profile stores the bookmarks, passwords, add-ons and preferences that belong to one browser user, and Selenium WebDriver can load a dedicated profile so every automated run starts from an identical, predictable browser state.
Selenium Firefox Profile
Firefox profile is the collection of settings, customization, add-ons and other personalization settings that can be done on the Firefox Browser. You can customize Firefox profile to suit your Selenium automation requirement.
Also, Firefox or any other browser handles the SSL certificates settings. So automating them makes a lot of sense along with the test execution code.
In short a profile is a userโs personal settings. When you want to run a reliable automation on a Firefox browser, it is recommended to make a separate profile. A dedicated profile also keeps your everyday browsing data out of the test run, which is the first thing to rule out when a Selenium script behaves differently on two machines.
Location of your profile folder in the disk
Firefox profile is just like different users using Firefox. Firefox saves personal information such as bookmarks, passwords, and user preferences which can be edited, deleted or created using the profile manager.
The screenshot below shows a profile folder as it appears on disk, named after the profile with a random prefix.
Location of profile is as follows
- For Windows > C:\Users\<username>\AppData\Roaming\Mozilla\Firefox\Profiles\profile_name.default
- For Linux > ~/.mozilla/firefox/profile_name.default/
- For Mac OS X > ~/Library/Application Support/Firefox/Profiles/profile_name.default/
In order to run a successful Selenium Test, a Firefox profile should be โ
- Easy to load
- Proxy settings if required
- Other user-specific settings based on automation needs
How to Set Firefox Profile for Selenium Tests
Let us see step by step how to create a Firefox profile.
Step 1) Close the Firefox browser
In the first step, close Firefox if it is already open. The profile manager will not start while a Firefox window is running.
Step 2) Open Run (Windows key + R) and type firefox.exe โp
The Run dialog should look like the screenshot below before you press OK.
Note: If it does not open you can try using full path enclosed in quotes.
- On 32 bit Windows: “C:\Program Files\Mozilla Firefox\firefox.exe” โp
- On 64 bit Windows (32-bit Firefox): “C:\Program Files (x86)\Mozilla Firefox\firefox.exe” โp
Step 3) Choose user profile
Now, a dialogue box named Firefox will open, as shown below.
Step 4) Create Profile
Select the Create Profile option shown in the next screenshot to start the wizard.
Now, Select option Create Profile from the window, and a wizard will open. Click on next.
Step 5) Give your profile name
Type a name for the automation profile in the field highlighted below and finish the wizard.
Now your profile is ready you can select your profile and open Firefox. From here the profile behaves like any other browser session, so a first WebDriver script will run against it unchanged.
You will notice that the new Firefox window will not show any of your Bookmarks and Favorite icons.
Note: The last selected profile, will load automatically at next Firefox launch. You will need to restart profile manager if you wish to change profiles.
Automation Script for Selenium
With the profile created, the next step is to load it from code. To access newly created Firefox profile in a Selenium WebDriver software test, we need to use WebDriverโs inbuilt class ProfilesIni and its method getProfile as shown below.
โ ๏ธ Version note: the snippets in this section are the original Selenium 2 form. In current Selenium releases the class lives in org.openqa.selenium.firefox.ProfilesIni โ the .internal sub-package was dropped โ and the profile is handed to the driver through FirefoxOptions. See the FirefoxOptions section below for the modern equivalent.
Selenium code for the profile
This is a code to implement a profile, which can be embedded in the Selenium code.
ProfilesIni profile = new ProfilesIni();
// this will create an object for the Firefox profile
FirefoxProfile myprofile = profile.getProfile("xyzProfile");
// this will Initialize the Firefox driver
WebDriver driver = new FirefoxDriver(myprofile)
Let us see the implementation of this code in the following examples.
Firefox Profile Example 1
The first example loads a profile by name. The screenshot below shows the same script inside the editor.
// import the package import java.io.File; import java.util.concurrent.TimeUnit; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxProfile; import org.openqa.selenium.firefox.internal.ProfilesIni; public class FirefoxProfile { public static void main(String[] args) { ProfilesIni profile = new ProfilesIni(); FirefoxProfile myprofile = profile.getProfile("xyzProfile"); // Initialize Firefox driver WebDriver driver = new FirefoxDriver(myprofile); //Maximize browser window driver.manage().window().maximize(); //Go to URL which you want to navigate driver.get("http://www.google.com"); //Set timeout for 5 seconds so that the page may load properly within that time driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); //close firefox browser driver.close(); } }
Explanation for the code
Below is the explanation of code line by line.
- Code line 2-7: First of all we need to import the package required to run the Selenium code.
- Code line 8: Make a public class “FirefoxProfile.”
- Code line 9: Make an object (you need to have basic knowledge of OOPs concepts).
- Code line 10-11: We need to initialize Firefox profile with the object of myprofile.
- Code line 13: Create object for Firefox.
- Code line 15: Maximize window.
- Code line 17: driver.get is used to navigate to the given URL.
- Code line 19: Set timeout is used to wait for some time so that browser may load the page before proceeding to next page.
- Code line 21: Close Firefox.
Let us see one more example.
Firefox Profile Example 2
The second example skips profiles.ini and points at the profile folder directly, as the editor screenshot shows.
import java.io.File; import java.util.concurrent.TimeUnit; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxProfile; import org.openqa.selenium.firefox.internal.ProfilesIni; public class FirefoxProfile2{ public static void main(String[] args) { // Create object for FirefoxProfile FirefoxProfilemyprofile=newFirefoxProfile (newFile("\c:users\AppData\MozillaFirefoxProfile_name.default ")); // Initialize Firefox driver WebDriver driver = new FirefoxDriver(myprofile); //Maximize browser window driver.manage().window().maximize(); //Go to URL driver.get("http://www.google.com"); //Set timeout driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); //close firefox browser driver.close(); }
Explanation for the code
Below is the explanation of code line by line.
- Code line 1-6: First of all we need to import the package required to run the Selenium code.
- Code line 8: Make a public class FirefoxProfile2.
- Code line 12: Make the object of myprofile by referring to the exact path.
- Code line 14: Create object for Firefox.
- Code line 16: Maximize window.
- Code line 18: driver.get is used to navigate to the given URL.
- Code line 20: Set timeout is used to wait for some time so that browser may load the page before proceeding to next page.
- Code line 22: Close Firefox.
Note that the path in this snippet is written exactly as the original tutorial shows it. On a real machine the backslashes must be escaped, for example “C:\\Users\\guru99\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\xyzProfile.default”.
How to Use a Firefox Profile in Selenium 4 with FirefoxOptions
Both examples above compile only against Selenium 2. Two things changed afterwards, and every current tutorial uses the newer form.
- ProfilesIni moved out of the internal sub-package, so the import is now org.openqa.selenium.firefox.ProfilesIni.
- The FirefoxDriver(FirefoxProfile) constructor was removed. The profile is attached to a FirefoxOptions object and the options object is passed to the driver.
- Selenium 4 timeouts take a java.time.Duration instead of a value plus a TimeUnit, so implicitlyWait(5, TimeUnit.SECONDS) becomes implicitlyWait(Duration.ofSeconds(5)).
The table below maps each legacy call to its replacement.
| Legacy call (Selenium 2) | Current call (Selenium 3 and 4) |
|---|---|
| import org.openqa.selenium.firefox.internal.ProfilesIni; | import org.openqa.selenium.firefox.ProfilesIni; |
| new FirefoxDriver(myprofile) | options.setProfile(myprofile); new FirefoxDriver(options) |
| implicitlyWait(5, TimeUnit.SECONDS) | implicitlyWait(Duration.ofSeconds(5)) |
| System.setProperty for geckodriver | Resolved automatically by Selenium Manager |
Rewritten against a current release, Example 1 looks like this.
import java.time.Duration; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxOptions; import org.openqa.selenium.firefox.FirefoxProfile; import org.openqa.selenium.firefox.ProfilesIni; public class FirefoxProfileSelenium4 { public static void main(String[] args) { ProfilesIni allProfiles = new ProfilesIni(); FirefoxProfile myprofile = allProfiles.getProfile("xyzProfile"); FirefoxOptions options = new FirefoxOptions(); options.setProfile(myprofile); WebDriver driver = new FirefoxDriver(options); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5)); driver.get("https://www.google.com"); driver.quit(); } }
The profile lookup itself is unchanged: ProfilesIni still reads profiles.ini from the Firefox application-data folder and getProfile still returns null when the name does not match a profile, so a null check is worth adding before the driver starts. The same options object also carries the arguments used elsewhere, such as the ones for maximizing or resizing the browser window.
How to Set Firefox Profile Preferences in Selenium
A saved profile is only half the story. Most automation needs a handful of preferences applied in code so the same behaviour follows the suite onto any machine. The setPreference method writes those values into the profile copy before Firefox launches.
FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("browser.download.folderList", 2); profile.setPreference("browser.download.dir", "C:\\selenium-downloads"); profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf"); profile.setPreference("dom.webnotifications.enabled", false); profile.setPreference("intl.accept_languages", "es"); FirefoxOptions options = new FirefoxOptions(); options.setProfile(profile); WebDriver driver = new FirefoxDriver(options);
The preferences below cover the cases that come up most often in day-to-day scripting.
| Preference | What it controls |
|---|---|
| browser.download.folderList | Set to 2 to use a custom download folder instead of the system default. |
| browser.download.dir | The absolute path Firefox saves downloads into. |
| browser.helperApps.neverAsk.saveToDisk | MIME types saved without showing the download dialog. |
| dom.webnotifications.enabled | Set to false to suppress web push notification prompts. |
| intl.accept_languages | The Accept-Language header, useful for localization runs. |
| general.useragent.override | Replaces the user agent string sent by the browser. |
Two limits are worth knowing. Preferences must be set before the driver is created, because WebDriver copies the profile at launch and later changes are ignored. WebDriver also reserves a small set of preferences it needs in order to talk to the browser, and it overwrites those whatever you assign. Because those values live in the profile rather than in the script, they also carry across a cross browser testing run without any change to the test code.
Common Firefox Profile Errors in Selenium and How to Fix Them
Profile problems usually surface as a compile error or as a browser that opens with the wrong settings. The table lists the failures reported most often, along with what causes each one.
| Symptom | Cause | Fix |
|---|---|---|
| The constructor FirefoxDriver(FirefoxProfile) is undefined | The constructor was removed after Selenium 2. | Wrap the profile in FirefoxOptions and pass the options object instead. |
| Cannot resolve import org.openqa.selenium.firefox.internal.ProfilesIni | The class moved out of the internal sub-package. | Import org.openqa.selenium.firefox.ProfilesIni. |
| NullPointerException on getProfile | The profile name does not match any entry in profiles.ini. | Reopen the profile manager and copy the name exactly, including case. |
| Your Firefox profile cannot be loaded. It may be missing or inaccessible. | Another Firefox instance already holds the profile, or the folder path is wrong. | Close every Firefox window, then verify the path against the locations listed above. |
| A preference has no effect | It was set after the driver started, or WebDriver reserves it. | Move every setPreference call above the FirefoxDriver constructor. |
If the browser starts correctly but the script still fails afterwards, the profile is probably not the cause. Working through exception handling in Selenium is usually the faster route from that point.







