DesiredCapabilities in Selenium with Example

In the Previous post, we have seen how to create Firefox Profile in Selenium. In this post, we will learn DesiredCapabilities in Selenium with Example.

Not all server implementations will support every WebDriver feature. DesiredCapabilities help to set the properties for WebDriver. A typical example can be to set the path of FirefoxDriver if local installation doesn’t point to the default settings. capabilities are nothing but a series of key/value pairs that express the essential features of a browser. If not able to understand much, don’t worry. It will be clear more with the below examples.

1. Using the preferred browser: The usual way to start a FirefoxDriver is as given below.

Now, let’s see how use desiredcapabilities to set the browser preferences. Use the below code for setting browser preference.

2. Changing the Proxy of the system: The preferred way to set the proxy manually at the system. But because of some reason , if you are not able to do so. Then you can use desiredcapabilities to set the proxy at your system to run the tests. But remember , this proxy changes in only for run time. Once the execution is over ,System will come to its original state.

Use the below code for setting proxy.

3. FirefoxProfile at run time with desired capabilities: In the previous post, we have seen how to use custom Firfox profile created by Firefox Profile Manager. We can also create desired firefox profile at run time and set the preferences. 

We can create this Firefox profile for activities like to ignore untrusted certificates errors, downloading file without popping up the download box( We will learn in details about file downloading in coming posts) etc.

Create Firefox Profile:

Example to use Firefox profile with desired capabilities:

4. Can be helpful in selenium Grid: Selenium Grid is helpful to provide parallel testing of the test cases. It can have multiple browser instances , different browser types and platforms. (You can learn about selenium Grid in next upcoming posts.)

DesiredCapability can help to select the browser and platform preferences as given below in the table.

Key Type Description
browserName string We can set the preferred browser name like (android|chrome|firefox|htmlunit|internet explorer|iPhone|iPad|opera|safari).
version string The browser version, or the empty string if unknown.
platform string It is used to specify the particular operating system or platform where test cases will be executing.Its values could be (WINDOWS|XP|VISTA|MAC|LINUX|UNIX|ANDROID). If platform is unknown , keyword ANY could be specified.

Example of using DesiredCapabilities in selenium Grid:

If you want to read more about Desired Capabilities, You can go to this Desired Capabilities Documentation.

Ask Question
Have any question or suggestion for us?Please feel free to post in Q&A Forum


Firefox Profiling in Selenium
How to capture the screen shot in selenium
Shekhar Sharma

Shekhar Sharma

Shekhar Sharma is founder of He is an automation engineer having more than 8 years of experience who loves troubleshooting in automation and finding innovative ways to solve the problems. His other leisurely activities includes playing harmonica, paintings, sketching portrait, watching movies and travelling etc.

You may also like...