White Box Testing
Test your code
   Home      selenium2WebDriver-BinaryProfileAndCookies
Selenium Webdriver firefox user profile modification
We can get firefox profile instance by FirefoxProfile
        FirefoxProfile profile = new FirefoxProfile();
To get already created named firefox profile instanciate ProfilesIni and call getProfile with firefox profile name
        ProfilesIni profilesIni = new ProfilesIni();

        // Clone the named profile               
        FirefoxProfile profile = profilesIni.getProfile("default");
Alternatively we can instanciate webdriver with already installed/created profile, but further we can not modify profile as in above case
        System.setProperty(“webdriver.firefox.profile”, profileName);
        WebDriver webDriver = new FirefoxDriver();
To set preferences for this particular profile
To see preference key and value type about:config in firefox address bar

To add an extension/plugins to install into this instance.

        File firebug = new File("C:Pluginsfirebug-1.7.3.xpi");
        profile.setPreference("extensions.firebug.currentVersion", "1.7.3");
 For invalid site certificate, If you are getting secure connection failed
For self signed certificate revert the above statement or call with argument true
Enabling by default disabled feature

Pass profile instance object to FirefoxDriver

        WebDriver driver = new FirefoxDriver(profile);
If firefox not installed in default location
        FirefoxBinary binary = new FirefoxBinary("/path/to/binary");
        WebDriver driver = new FirefoxDriver(binary, profile);
To add a cookie

        Cookie cookie1 = new Cookie("key1", "value1");
        Cookie cookie2 = new Cookie("key2", "value2");

To get all cookies and display them

        Set<Cookie> allCookies = driver.manage().getCookies();
        for (Cookie loadedCookie : allCookies) {
               System.out.println(String.format("%s -> %s", loadedCookie.getName(), loadedCookie.getValue()));

You can delete cookies in 3 ways
  • By cookie name

  • By loaded Cookie instance

  • Delete all the cookies