Time for action – setting Firefox preferences - Selenium

Imagine that you wanted to have your site as the startup page for Firefox. To do this we will need to update the browser.startup.homepage preference. Follow these steps:

  1. Let's start by creating the FirefoxProfile object:

    FirefoxProfile profile = new FirefoxProfile();
  2. Now we will set the preference:

    profile.setPreference("browser.startup.homepage","https://www.wisdomjobs.com");
  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(profile);
  4. Run your test. The final code should look like the following:

What just happened?

We have just seen that we can manipulate Firefox settings before the browser is loaded. This can be useful if you need to get extra information out of the browser or if we have a few things that need tweaking.

If you had installed Firefox in a different place, you would have had to instantiate the FirefoxBinary class with details of it:

FirefoxBinary binary = new FirefoxBinary("/path/to/binary");

driver = new FirefoxDriver(binary);

If you need to update both the Firefox Profile and the Firefox Binary, you can simply pass both of them through the constructor as follows:

As you can see, it's fairly simple to load Firefox if it isn't installed in the usual place.

Installing a Firefox add-on

One of the most useful features of Firefox is the ability to install add-ons to enhance the user experience. This enhanced experience can mean that web applications act differently when the add-on is installed.

Let's have a look at how we can install an add-on into our profile before we start the browser.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Selenium Topics