Defining Firefox Profile preferences using Selenium Webdriver

Some times, you may need to update the preferences within Firefox. We can do this by instantiating a Firefox Profile object and then update the settings.

We will then need to pass this object into FirefoxDriver which will load the profile with your defined settings.

You can check them using command "about:config" in the borwser. It will display a warning message and then asks you to proceed if required. Becarefull when doing any changes.

Let us assume that you wanted to have google as the startup page for Firefox. To do this we will need to update the browser.startup.homepage preference.

Follow below steps to add a website as your homepage:

1. Let's first start by creating the FirefoxProfile object:
FirefoxProfile ffprofile= new FirefoxProfile();

2. Now we will set the preference by using the below method:

3. To get the profile to be used, we need to pass it in to the driver. To do this, we need
to do the following:
driver = new FirefoxDriver(ffprofile);

4. Now run your test. The final code should look like the following:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.testng.annotations.Test;

public class FireFoxProfileExample {

WebDriver driver;

public void testExamples(){
FirefoxProfile profile = new FirefoxProfile();
driver = new FirefoxDriver(profile);

WebElement element = driver.findElement("q"));


You can check if that has applied to the firefox or not. Please enter "about:config" in address bar, and type "browser.startup.homepage".
It will display the website that you have added.
The below screen shot shows "" which is added by using the code.
Firefox profile preferences

Selenium Tutorials: 


The example is greate but in fact the command "profile.setPreference..." not exist (( in Netbean ide.

you need to use the object of firefoxProfile to set preferences.

For Eg:

FireFoxProfile fprofile = new FireFoxprofile();
WebDriver driver = new FirFoxDriver(fprofile);

Do you know how to use that to set certain mime-types to auto-open with a given app, e.g. for `txt/plain` to open with `/usr/bin/vim`?

org.openqa.selenium.firefox.internal.ProfilesIni - needs to be added for above

i have written java code in eclipse in order to open fire_fox browser using keyword driven concept but unable to open fire_fox browser

Are the set preferences applied to only run-time execution OR set permanently to browser?

Add new comment