org.openqa.selenium.chrome
Class ChromeOptions

java.lang.Object
  extended by org.openqa.selenium.chrome.ChromeOptions

public class ChromeOptions
extends java.lang.Object

Class to manage options specific to ChromeDriver.

Example usage:


 ChromeOptions options = new ChromeOptions()
 options.addExtensions(new File("/path/to/extension.crx"))
 options.setBinary(new File("/path/to/chrome"));

 // For use with ChromeDriver:
 ChromeDriver driver = new ChromeDriver(options);

 // For use with RemoteWebDriver:
 DesiredCapabilities capabilities = DesiredCapabilities.chrome();
 capabilities.setCapability(ChromeOptions.CAPABILITY, options);
 RemoteWebDriver driver = new RemoteWebDriver(
     new URL("http://localhost:4444/wd/hub"), capabilities);
 

Since:
Since chromedriver v17.0.963.0

Field Summary
static java.lang.String CAPABILITY
          Key used to store a set of ChromeOptions in a DesiredCapabilities object.
 
Constructor Summary
ChromeOptions()
           
 
Method Summary
 void addArguments(java.util.List<java.lang.String> arguments)
          Adds additional command line arguments to be used when starting Chrome.
 void addArguments(java.lang.String... arguments)
           
 void addExtensions(java.io.File... paths)
           
 void addExtensions(java.util.List<java.io.File> paths)
          Adds a new Chrome extension to install on browser startup.
 void setBinary(java.io.File path)
          Sets the path to the Chrome executable.
 org.json.JSONObject toJson()
          Converts this instance to its JSON representation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CAPABILITY

public static final java.lang.String CAPABILITY
Key used to store a set of ChromeOptions in a DesiredCapabilities object.

See Also:
Constant Field Values
Constructor Detail

ChromeOptions

public ChromeOptions()
Method Detail

setBinary

public void setBinary(java.io.File path)
Sets the path to the Chrome executable. This path should exist on the machine which will launch Chrome. The path should either be absolute or relative to the location of running ChromeDriver server.

Parameters:
path - Path to Chrome executable.

addArguments

public void addArguments(java.lang.String... arguments)
Parameters:
arguments - The arguments to use when starting Chrome.
See Also:
addArguments(java.util.List)

addArguments

public void addArguments(java.util.List<java.lang.String> arguments)
Adds additional command line arguments to be used when starting Chrome. For example:

   options.setArguments(
       "load-extension=/path/to/unpacked_extension",
       "allow-outdated-plugins");
 

Each argument may contain an option "--" prefix: "--foo" or "foo". Arguments with an associated value should be delimitted with an "=": "foo=bar".

Parameters:
arguments - The arguments to use when starting Chrome.

addExtensions

public void addExtensions(java.io.File... paths)
Parameters:
paths - Paths to the extensions to install.
See Also:
addExtensions(java.util.List)

addExtensions

public void addExtensions(java.util.List<java.io.File> paths)
Adds a new Chrome extension to install on browser startup. Each path should specify a packed Chrome extension (CRX file).

Parameters:
paths - Paths to the extensions to install.

toJson

public org.json.JSONObject toJson()
                           throws java.io.IOException,
                                  org.json.JSONException
Converts this instance to its JSON representation.

Returns:
The JSON representation of these options.
Throws:
java.io.IOException - If an error occurs while reading the extension files from disk.
org.json.JSONException - If an error occurs while encoding these options as JSON.


Copyright © 2012. All Rights Reserved.