Change Firefox Profile Using WebDriver

Firefox profile is just a particular folder where you save all Firefox related settings data in. These data includes such as your saved password, installed plugins, favorite homepage etc. The profile folder is separate from Firefox software program’s folder. So when you crash or uninstall the program, all your profile’s setting information can still be found. If you want to clear your profile information, you do not need to uninstall the program also.

How can you find your profile folder?

  1. Click menu button in right corner then click Question mark in popup menu.
    Find Firefox profile folder Click Menu then Question button
  2. Click “Troubleshooting Information” menu in popup menu.
    Find Firefox profile folder Click Troubleshooting Information menu
  3. Click “Show Folder” below “Application Basics” area. Then your profile folder will be open.
    Find Firefox profile folder Click Show Folder under Application Basics section
  4. You can also open your profile folder by following method.
    Type following string in your windows start menu search box.
    %APPDATA%\Mozilla\Firefox\Profiles\
    Find Firefox profile folder By command

What’s data do your Firefox profile folder store?

Passwords: logins.json and key3.db store your passwords.

Personal dictionary: persdict.dat stores any custom words added to the dictionary of Firefox.

Cookies: cookies.sqlite store the cookie data.

Bookmarks, Downloads and Browsing History: places.sqlite contains following 3 kinds of data. 1) Bookmarks. 2)Downloaded files. 3) Visited websites.
Folder bookmarkbackups stores backup files of bookmark, you can use it to restore bookmarks if you lost it.

Site-specific preferences: The content-prefs.sqlite and permissions.sqlite file store permissions or zoom levels on site by site basis.

Search engines: search.json.mozlz4 saves search engines which user installed in Firefox Search tool bar.

Autocomplete history: formhistory.sqlite stores your search history in Firefox search bar. It also stores the data you’ve typed in html form fields such as input text box.

READ :   How To Select The Effective XPath For Web Element In Webdriver

DOM storage: DOM storage is designed to be a replacement for cookie. The data stored in DOM storage will be more secure, more larger and moe easy to use. File webappsstore.sqlite store websites data and chromeappsstore.sqlite stores pages related data.

Security certificate settings: cert8.db stores settings of security certificate and any imported SSL certificates.

Security device settings: secmod.db is a database to store security device’s data.

Extensions: extensions folder stores files for all installed extensions.

Download actions: mimeTypes.rdf  stores your choices that notify Firefox how to proceed a download file when it meets a specific file type.

Stored session: sessionstore.js saves the latest opened windows and tabs.

User preferences: prefs.js saves settings for customized user preference. If user.js file exist then it’s data will override any changed preferences.

Toolbar customization: xulstore.json  stores settings for window size/position or toolbar.

Plugin MIME type: pluginreg.dat  stores installed plugins related Internet media types.

How to see current Firefox browser preferences?

  1. Open a Firefox browser.
  2. Input “about:config” in the address text box.
  3. Click Enter key, you will see below picture.
    input about config command in Firefox address bar
  4. Click “I’ll be careful, I promise!” blue button. You can see the preferences list page. You can use following java code to set or change the preference’s value.
     /* Init a FirefoxProfile object first. */
    
     FirefoxProfile ffProfile = new FirefoxProfile();
    
    /* Set preference browser.startup.homepage's value 
       to http://www.yahoo.com. You can see a list of preferences name
       by input about:config in Firefox address bar.
    */
    
     ffProfile.setPreference("browser.startup.homepage", "http://www.yahoo.com");

    firefox preference list page

How to update Firefox preferences Using Selenium WebDriver?

  1. Initiate a Firefox Profile object.
  2. Pass the above object to FirefoxDriver.
  3. FirefoxDriver will open a Firefox browser with the settings you just set.

Below code will set yahoo.com as the startup page. See comments for detail explanation.

 /* Init a FirefoxProfile object first. */
 FirefoxProfile ffProfile = new FirefoxProfile();
 
 /* Set preference browser.startup.homepage's value to http://www.yahoo.com.
 * You can see a list of preferences by input about:config in address bar.
 * */
 ffProfile.setPreference("browser.startup.homepage", "http://www.yahoo.com");
 
 /* Use the ffProfile to create a FirefoxDriver object. 
    When the browser startup, you will see the home page 
    changed to http://www.yahoo.com.
 */
 WebDriver firefoxDriver = new FirefoxDriver(ffProfile);
 
 /* Maximize the browser window. */
 firefoxDriver.manage().window().maximize();
 
 /* Sleep 100 seconds, you can check whether the 
    preference browser.startup.homepage's 
    value has changed or not during this period.*/
 Thread.sleep(100000);
 
 /* Quit webdriver object and close the browser. */
 firefoxDriver.quit();

Download “TestChangeFirefoxProfile.zip” TestChangeFirefoxProfile.zip – Downloaded 32 times – 732 B

(Visited 317 times, 1 visits today)

Leave a Reply

Your email address will not be published. Required fields are marked *