ChromeOptions to configure Chrome Sessions in Selenium

This tutorial is in continuation to our previous tutorial which is on use of DesiredCapabilities in Selenium WebDriver to set the browser’s properties. The Desired Capabilities class is not used anymore to handle the browser’s properties in Selenium which is most probably due to change in the architecture of the latest versions of the browsers. If you want to set the capability properties for your browser then you need to use browser specific options properties, that is why today we are going to discuss the ChromeOptions class of Selenium remote library.

Let’s start today with the options properties for chrome, further, we will discuss remaining browser options class for the rest of the web browsers in subsequent tutorials.

When we use DesiredCapabilities class to handle the browser-based session (say Chrome here) then it underlines the ChromeDriver() which indicates that it has been deprecated in Java programming language. However, it is available to use in Python, Ruby and other programming languages. See image below:

ChromeOptions alternative to DesiredCapabilitiesWhat is ChromeOptions in Selenium WebDriver?

ChromeOptions is a class in Selenium which is used to set the capability and customization and configuration of the ChromeDriver session as well.  This class inherits the MutableCapabilities class. Here is the library path:

Click here to know more about it.

MutableCapabilities class first came in existence with Selenium 3.6.0 and now all the options classes for respective browsers extends this class in Java. We need to import below package to work with Chrome Options in Java to customize the Chrome sessions.

What are the uses of ChromeOptions in Selenium?

ChromeOptions has all the uses which DesiredCapabilities was doing, but, it is only dedicated to one browser. Let’s have a look over some of the uses of the Chrome Options.

  • It is used to get and set capabilities in Chrome
  • Chrome Options supports to add the extension to the browser at runtime
  • It helps to add binary at runtime
  • ChromeOptions is used to handle the proxy while running test automation
  • We use ChromeOptions in Selenium Grid to remotely set the Chrome session in node machines

We will further discuss the implementation of the above uses in a separate article at inviul.com.

Methods of ChromeOptions class

Here is the list of some of the methods of the ChromeOptions class which we use them whenever required as per the criteria.

  • addArguments(arguments)
  • addEncodedExtensions()
  • addExtensions()
  • getCapability()
  • setCapability()
  • getPlatform()
  • setAcceptInsecureCerts()
  • setBinary()
  • setProxy()
  • setExperiementalOption()
  • setPageLoadStrategy()
  • setUnhandledPromptBehaviour()
  • getBrowserName()
  • getVersion()

How to set capability with ChromeOptions in Selenium WebDriver?

Following program uses Chrome Options class to set the capability to the ChromeDriver. Here we are setting browser name and Windows 10 as the platform with the help of Chrome options. Further, we set the instance of ChromeOptions as the argument in ChromeDriver().

Let’s have an eye to the programming part.

This was all about setting ChromeOptions as the capability in Selenium WebDriver. If you have any queries, suggestions or feedback then feel free to write below in the comment form and don’t miss to join our Facebook group for quick and latest updates on Selenium WebDriver and Automation testing as well.

Join Inviul fb group

Leave a Reply