Pass Chrome options as capabilities

Learn how to pass Chrome options that are not a part of standard capabilities.

Starting in Selenium version 3.6.0, the ChromeOptions class in Java also implements the Capabilities interface, allowing you to specify other WebDriver capabilities not specific to ChromeDriver.

The following code example below shows how to pass Chrome Options as capabilities.

Copy
Chrome Options with switches
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("/path/to/extension.crx"));
options.addArguments("--start-maximized");
options.addArguments("--disable-web-security");
options.addArguments("--allow-insecure-localhost");
options.addArguments("--ignore-urlfetcher-cert-requests")
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
Copy
Chrome Options with preferences
ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("ssl.error_override_allowed", true);
options.setExperimentalOption("prefs", prefs);
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
Copy
Chrome Options with switches Protractor JS
 capabilities: {
  browserName: 'chrome',
  chromeOptions: {
     args: [ "--headless", 
             "--disable-gpu", 
             "--window-size=800,600",
             "--debuggerAddress=127.0.0.1:12633" ]
   }
}
Copy
Chrome://flags Chrome driver Protractor JS example
capabilities: {
    'platformName' : 'Windows',
    'platformVersion' : '10',
    'browserName' : 'Chrome',
    'browserVersion' : '77',
    'resolution' : '1280x1024',
    'location' : 'US East',
                                securityToken: '',
                                "goog:chromeOptions":  {
        args: ["" ],
        extensions: []
    }
  },

To learn more about Chrome driver capabilities, a complete list of switches, and preference options, see the following articles:

Also see the Perfecto Knowledgebase.