Change Firefox Profile Using WebDriver

A Firefox profile is just a particular folder where you save all Firefox-related settings data in. These data include such as your saved password, installed plugins, favorite homepage, etc. The profile folder is separate from the 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.

1. How can you find your profile folder?

  1. Click the Open Application Menu button ( 3 short horizontal lines) on the right corner of the Firefox web browser then click the Question mark in the popup menu bottom area.
  2. Click the Troubleshooting Information menu item in the popup menu.
  3. Click the Show Folder button in the Application Basics area. Then your profile folder will be open.
  4. You can also open your profile folder by typing the %APPDATA%\Mozilla\Firefox\Profiles\ string in your windows starts menu search box.

2. What’s data do your Firefox profile folder store?

  1. Passwords: logins.json and key3.db store your passwords.
  2. Personal dictionary: persdict.dat stores any custom words added to the dictionary of Firefox.
  3. Cookies: cookies.sqlite store the cookie data.
  4. Bookmarks, Downloads and Browsing History: places.sqlite contains following 3 kinds of data. 1) Bookmarks. 2)Downloaded files. 3) Visited websites.
  5. Folder bookmarkbackups: stores backup files of bookmark, you can use it to restore bookmarks if you lost them.
  6. Site-specific preferences: The content-prefs.sqlite and permissions.sqlite file store permissions or zoom levels on site by site basis.
  7. Search engines: search.json.mozlz4 saves search engines which user installed in Firefox Search tool bar.
  8. 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.
  9. 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.
  10. Security certificate settings: cert8.db stores settings of security certificate and any imported SSL certificates.
  11. Security device settings: secmod.db is a database to store security device’s data.
  12. Extensions: extensions folder stores files for all installed extensions.
  13. Download actions: mimeTypes.rdf  stores your choices that notify Firefox how to proceed a download file when it meets a specific file type.
  14. Stored session: sessionstore.js saves the latest opened windows and tabs.
  15. User preferences: prefs.js saves settings for customized user preference. If user.js file exist then it’s data will override any changed preferences.
  16. Toolbar customization: xulstore.json  stores settings for window size/position or toolbar.
  17. Plugin MIME type: pluginreg.dat  stores installed plugins related Internet media types.

3. How to see current Firefox browser preferences?

  1. Open a Firefox browser.
  2. Input “about:config” in the address text box.
  3. Click the Enter key, you will see a web page with the warning text This might void your warranty!.
  4. Click the “I’ll be careful, I promise!” blue button on the above web page. You can see the preferences list page. You can use the 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 the Firefox address bar.
    */
    
     ffProfile.setPreference("browser.startup.homepage", "http://www.yahoo.com");

3. 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.
  4. The below code will set yahoo.com as the startup page. See comments for the detailed 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 the 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();

Leave a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.