public class ChromeOptions extends Object
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);
// or alternatively:
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);
// 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);
Modifier and Type | Field and Description |
---|---|
static String |
CAPABILITY
Key used to store a set of ChromeOptions in a
DesiredCapabilities
object. |
Constructor and Description |
---|
ChromeOptions() |
Modifier and Type | Method and Description |
---|---|
void |
addArguments(List<String> arguments)
Adds additional command line arguments to be used when starting Chrome.
|
void |
addArguments(String... arguments) |
void |
addExtensions(File... paths) |
void |
addExtensions(List<File> paths)
Adds a new Chrome extension to install on browser startup.
|
boolean |
equals(Object other) |
int |
hashCode() |
void |
setBinary(File path)
Sets the path to the Chrome executable.
|
void |
setBinary(String path)
Sets the path to the Chrome executable.
|
void |
setExperimentalOptions(String name,
Object value)
Sets an experimental option.
|
org.json.JSONObject |
toJson()
Converts this instance to its JSON representation.
|
public static final String CAPABILITY
DesiredCapabilities
object.public void setBinary(File path)
path
- Path to Chrome executable.public void setBinary(String path)
path
- Path to Chrome executable.public void addArguments(String... arguments)
arguments
- The arguments to use when starting Chrome.addArguments(java.util.List)
public void addArguments(List<String> arguments)
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".
arguments
- The arguments to use when starting Chrome.public void addExtensions(File... paths)
paths
- Paths to the extensions to install.addExtensions(java.util.List)
public void addExtensions(List<File> paths)
paths
- Paths to the extensions to install.public void setExperimentalOptions(String name, Object value)
ChromeOptions
API.name
- Name of the experimental option.value
- Value of the experimental option, which must be convertible
to JSON.public org.json.JSONObject toJson() throws IOException, org.json.JSONException
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 © 2013. All Rights Reserved.