Chrome Options & Desired Capabilities in Selenium

โšก Smart Summary

Chrome Options and Desired Capabilities in Selenium WebDriver control how the Chrome browser launches and behaves during automated tests. Together they configure arguments, extensions, SSL handling, and cross-browser settings, making test runs flexible, repeatable, and ready for Selenium Grid execution.

  • ๐ŸŒ ChromeOptions: Customizes sessions with arguments like start-maximized, incognito, and headless.
  • โš™๏ธ Desired Capabilities: Sets browser name, platform, version, and SSL certificate acceptance.
  • ๐Ÿงฉ Extensions: Load a CRX file through automation instead of installing it manually.
  • ๐Ÿ•ต๏ธ Incognito and headless: Reusable code runs private or background sessions for CI pipelines.
  • ๐Ÿ–ฅ๏ธ Selenium Grid: Capabilities enable cross-browser, distributed test execution.
  • โš ๏ธ Selenium 4 note: DesiredCapabilities is deprecated; pass ChromeOptions directly to the driver.

Chrome Options and Desired Capabilities in Selenium WebDriver

What is Chrome Options Class?

The Chromeoptions Class is a concept in Selenium WebDriver for manipulating various properties of the Chrome driver. The Chrome options class is generally used in conjunction with Desired Capabilities for customizing Chrome driver sessions. It helps you perform various operations like opening Chrome in maximized mode, disable existing extensions, disable pop-ups, etc.

Example:

Below example shows a way to open Chrome browser in maximized mode using ChromeOptions class. We need to pass an instance of ChromeOptions class to the web driver initialization.

ChromeOptions options = new ChromeOptions()
options.addArgument("start-maximized");
ChromeDriver driver = new ChromeDriver(options);

Below are the list of available and most commonly used arguments for ChromeOptions class

  • start-maximized: Opens Chrome in maximize mode
  • incognito: Opens Chrome in incognito mode
  • headless: Opens Chrome in headless mode
  • disable-extensions: Disables existing extensions on Chrome browser
  • disable-popup-blocking: Disables pop-ups displayed on Chrome browser
  • make-default-browser: Makes Chrome default browser
  • version: Prints chrome browser version
  • disable-infobars: Prevents Chrome from displaying the notification ‘Chrome is being controlled by automated software

Desired Capabilities class

Desired Capabilities Class is used to modify multiple properties of web drivers. It provides key-value pairs to change individual properties of web drivers such as browser name, browser platform, etc. A common method of Desired Capabilities class is the setCapability method. It is mostly used with Selenium Grid, where the same test case needs to be executed on different browsers.

Example:

Below example shows the way to enable chrome browser to accept SSL certificates on websites by default using Desired Capabilities for Chrome class.

// Create an object of desired capabilities class with Chrome driver
DesiredCapabilities SSLCertificate = DesiredCapabilities.chrome();
// Set the pre defined capability โ€“ ACCEPT_SSL_CERTS value to true
SSLCertificate.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
// Open a new instance of chrome driver with the desired capability
WebDriver driver = new ChromeDriver(SSLCertificate);

Below are the most commonly used pre-defined capability types.

Capability Name Description
ACCEPT_SSL_CERTS This property tells the browser to accept SSL Certificates by default
PLATFORM_NAME This property is used to set the operating system platform used to access the web site
BROWSER_NAME This property is used to set the browser name for a web driver instance
VERSION This property to used to set the browser version

Chrome Options for Adblocker extension

Adblocker extension of the Chrome browser can be handled using ChromeDriver Options and Desired Capabilities class. Below are the steps to access AdBlocker extension on the Chrome browser using Desired Capabilities class.

Step 1) AdBlocker extension must be installed on Chrome browser before using Chrome Options class

Step 2) Extract the CRX File corresponding to AdBlocker extension through http://crxextractor.com/

Step 3) Pass the downloaded CRX File path to Chrome Options class

Step 4) Instantiate the web driver using the desired capabilities class and Chrome Options in Selenium object

Example:

Below example demonstrates how to activate ad blocker extension on the Chrome browser using Chrome Options and Desired Capabilities class.

ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("Path to CRX File"));
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);

Extract CRX File

Below steps demonstrate the process of extracting CRX File through Ad Blocker through the web site – http://crxextractor.com/

Step 1) Go to http://crxextractor.com/ and click start button

Extract CRX File

Step 2) Enter the chrome extension โ€“ Ad Blocker URL under the textbox. URL for Adblock on Chrome web store is https://chrome.google.com/webstore/detail/adblock-%E2%80%94-best-ad-blocker/gighmmpiobklfepjocnamgkkbiglidom

and click ok

Extract CRX File

Step 3) On clicking the OK Button, the label of the button will change to Get .CRX as below. Click on Get .CRX button, CRX file corresponding to the extension will be downloaded

Extract CRX File

Step 4) Save the file onto the local machine, make a note of the path saved. The next step is to pass the saved path to Chrome Options class

Sample Code:

  1. You will see ads at https://demo.guru99.com/ as below

Extract CRX File

  1. With AdBlocker extension enabled on Chrome browser ads should be disabled
package adblock;
import java.io.File;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;


public class AdblockDemo {
public static void main(String[] args)  {
	
	System.setProperty("webdriver.chrome.driver","X://chromedriver.exe");		
	ChromeOptions options = new ChromeOptions();
	options.addExtensions(new File("X://extension_3_40_1_0.crx")); 
	DesiredCapabilities capabilities = new DesiredCapabilities();
	capabilities.setCapability(ChromeOptions.CAPABILITY, options);
	options.merge(capabilities);
	ChromeDriver driver = new ChromeDriver(options);
	driver.get("https://demo.guru99.com/test/simple_context_menu.html");
	driver.manage().window().maximize();
	//driver.quit();
	}
	
}

Code Explanation:

  1. Initially, you need to set the path to the chromedriver.exe file using set property method since you are using Chrome Browser for testing
  2. You need to set the path to CRX File to add extensions method
  3. Then you need to create an object of Chrome Desired Capabilities in Selenium class and pass it to web driver instance. From Selenium 3.8.1 version, driver capabilities class is deprecated and you need to merge capabilities object with Chrome Options object before passing the same as an argument to Chrome Driver constructor
  4. Open the URL – https://demo.guru99.com/test/simple_context_menu.html with Ad Blocker extension enabled
  5. Maximize and close the browser

NOTE: We are enabling AdBlocker extension on the Chrome browser through automation script instead of manually enabling Adblocker extension on the Chrome browser. CRX File is a way to access ad blocker extension using automation script

Output:

Chrome browser will be enabled with AdBlocker extension enabled as below without any ads

Extract CRX File

Beyond loading extensions, ChromeOptions also controls how the browser window itself runs.

Chrome Options for Incognito mode

Chrome Options can be used for incognito mode by using the pre-defined argument โ€“incognito.

Below is the sample code to accomplish the same.

Sample Code:

package test;
import java.io.File;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;

public class Incognito{
public static void main(String[] args) {
	// TODO Auto-generated method stub
	System.setProperty("webdriver.chrome.driver","X://chromedriver.exe");
	ChromeOptions options = new ChromeOptions();
	options.addArguments("--incognito");
	DesiredCapabilities capabilities = new DesiredCapabilities();
	capabilities.setCapability(ChromeOptions.CAPABILITY, options);
	options.merge(capabilities);
	ChromeDriver driver = new ChromeDriver(options);		
	driver.get("https://demo.guru99.com/test/simple_context_menu.html");
	driver.manage().window().maximize();		
	//driver.quit();
	}
	}

Code Explanation:

  1. Initially, you need to set the path to the chromedriver.exe file using set property method since you are using Chrome Browser for testing
  2. Then you need to create an object of Chrome Options class and pass it to web driver instance. Since we want to open Chrome browser in incognito mode, you need to pass the argument โ€“incognito to Chrome Options class.
  3. Next, create an object of Desired Capabilities class and merge the Desired Capabilities class object with Chrome Options class object using merge method
  4. You need to create an object of Chrome Driver class and pass the Chrome Options object as an argument
  5. Finally, we need to pass the URL – https://demo.guru99.com/test/simple_context_menu.html to the driver.get method
  6. Maximize and close the browser

Output:

The chrome browser window will be opened in Incognito mode as below

Chrome Options For Incognito Mode

Chrome Options for Headless Chrome

A Headless browser runs in the background. You will not see the browser GUI or the operations been operated on it.

Chrome Options for running Chrome browser in headless mode can be accomplished by using the predefined arguments โ€“headless.

Sample code to accomplish it is mentioned below.

Example:

package test;
import java.io.File;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;


public class HeadlessModeDemo {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.setProperty("webdriver.chrome.driver","X://chromedriver.exe");
		ChromeOptions options = new ChromeOptions();
		options.addArguments("--headless");
		DesiredCapabilities capabilities = new DesiredCapabilities();
		capabilities.setCapability(ChromeOptions.CAPABILITY, options);
		options.merge(capabilities);
		ChromeDriver driver = new ChromeDriver(options);		
		driver.get("https://demo.guru99.com/");
		driver.manage().window().maximize();
		String title = driver.getTitle();
		System.out.println("Page Title: " +title);
		driver.quit();
		}


}

Code Explanation:

  1. Initially, you need to set the path to the chromedriver.exe file using set property method since you are using Chrome Browser for testing
  2. Next, create an object of Chrome Options class and pass it to web driver instance. Since we want to open Chrome browser in headless mode, we need to pass the argument โ€“headless to Chrome Options class.
  3. Create an object of DesiredCapabilities Chrome class and merge the Desired Capabilities class object with Chrome Options class object using merge method
  4. Create an object of Chrome Driver class and pass the Chrome Options Selenium object as an argument
  5. Finally, we need to pass the URL – https://demo.guru99.com/ to the driver.get method
  6. Print the page title and close the browser

Output

The browser will not be visible for the above code as Chrome will be working in Headless mode. Page title will be fetched and displayed as below.

Chrome Options For Headless Chrome

FAQs

Yes. Selenium 4 deprecated DesiredCapabilities in favor of browser Options classes such as ChromeOptions. In Selenium 3 you merged them; in Selenium 4 you pass ChromeOptions directly to the driver.

Call addArguments with several flags, for example options.addArguments with start-maximized and incognito. You can chain multiple calls too. Each argument customizes how the Chrome session launches.

addArguments passes command-line flags like headless or incognito to Chrome. addExtensions loads a packaged .crx extension file into the session. Both customize behavior but serve different purposes.

Yes. AI assistants such as Copilot scaffold ChromeOptions and capability setups, suggest argument names, and explain deprecated APIs. Always review output, because flag names and Selenium versions change frequently.

AI self-healing tools auto-update arguments, detect flaky flags, and suggest stable replacements after Chrome upgrades. They cut maintenance for headless runs and capability mismatches across CI environments.

Yes. ChromeOptions works with RemoteWebDriver for Grid execution. You attach the options to the remote session, letting the same configuration run across distributed machines and browsers.

This usually means the ChromeDriver and Chrome browser versions do not match. Install a matching ChromeDriver, or use Selenium Manager in Selenium 4 to resolve the driver automatically.

Use an experimental option: a prefs map with download.default_directory passed via setExperimentalOption. Chrome then saves files to that folder automatically during automated tests.

Summarize this post with: