Class HtmlUnitDriverOptions
- All Implemented Interfaces:
Serializable,org.openqa.selenium.Capabilities
HtmlUnitDriver.
Example usage:
HtmlUnitDriverOptions options = new HtmlUnitDriverOptions()
.setWebClientVersion(BrowserVersion.FIREFOX_ESR)
.setJavaScriptEnabled(true);
// For use with HtmlUnitDriver:
HtmlUnitDriver driver = new HtmlUnitDriver(options);
// For use with RemoteWebDriver:
RemoteWebDriver driver = new RemoteWebDriver(
new URL("http://localhost:4444/"),
new HtmlUnitDriverOptions());
Getting/setting HtmlUnitDriver options:
In addition to methods for reading and writing specific HtmlUnitDriver options, you can use
the standard MutableCapabilities API:
Capabilities.is(String)getCapability(String)setCapability(String, Object)
Example usage:
HtmlUnitDriverOptions options = new HtmlUnitDriverOptions();
boolean popupBlockerEnabled = options.is(HtmlUnitOption.optPopupBlockerEnabled);
// NOTE: See "Getting individual browser version traits" below
String browserLanguage = (String) options.getCapability(BrowserVersionTrait.optBrowserLanguage);
options.setCapability(HtmlUnitOption.optGeolocationEnabled, true);
Getting individual browser version traits:
HtmlUnitDriverOption contains a BrowserVersion which can be read and written directly:
Capabilities API. For example:
HtmlUnitDriverOptions options = new HtmlUnitDriverOptions(BrowserVersion.EDGE);
// System time zone accessed via BrowserVersion API
TimeZone viaBrowserVersion = options.getWebClientVersion.getSystemTimezone();
// System time zone accessed via standard Capabilities API
TimeZone viaCapabilityName = (TimeZone) options.getCapability(BrowserVersionTrait.optSystemTimezone);
NOTE: Although HtmlUnitDriverOptions objects are mutable (their properties can be altered),
the individual traits of the BrowserVersion object within these objects cannot be altered:
HtmlUnitDriverOptions options = new HtmlUnitDriverOptions(BrowserVersion.CHROME);
options.setCapability(BrowserVersionTrait.optUserAgent, "HtmlUnitDriver emulating Google Chrome");
// => UnsupporterOperationException: Individual browser version traits are immutable; 'optUserAgent' cannot be set
- Since:
- HtmlUnitDriver v4.22.0
- Author:
- Scott Babcock, Ronald Brill
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.HtmlUnitDriverOptions(Map<String, Object> optionsMap) Constructs HtmlUnitDriverOptions from a map of options.HtmlUnitDriverOptions(BrowserVersion version) Constructs HtmlUnitDriverOptions with a specificBrowserVersion.HtmlUnitDriverOptions(BrowserVersion version, boolean enableJavascript) Constructs HtmlUnitDriverOptions with a specificBrowserVersionand JavaScript support enabled/disabled.HtmlUnitDriverOptions(org.openqa.selenium.Capabilities source) Constructs HtmlUnitDriverOptions from an existingCapabilitiesobject. -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyOptions(WebClientOptions target) Apply values from this HtmlUnitDriver options object to the specifies target.getCapability(String capabilityName) protected ObjectgetExtraCapability(String capabilityName) Returns the configuredBrowserVersionused by the underlying WebClient.importOptions(WebClientOptions source) Import values from the specified source into this HtmlUnitDriver options object.booleanReturns whether images are downloaded automatically.booleanReturns whether JavaScript execution is enabled.setBrowserVersion(String browserVersion) voidsetCapability(String capabilityName, Object value) setDownloadImages(boolean downloadImages) Enables or disables automatic image downloading.setJavaScriptEnabled(boolean enableJavascript) Enables or disables JavaScript execution.setSSLClientCertificateKeyStore(InputStream keyStoreInputStream, String keyStorePassword, String keyStoreType) Sets the SSL client certificate key store from anInputStream.setSSLClientCertificateKeyStore(URL keyStoreUrl, String keyStorePassword, String keyStoreType) Sets the SSL client certificate key store using a URL.setSSLClientCertificateKeyStore(KeyStore keyStore, char[] keyStorePassword) Sets the SSL client certificate key store from an existingKeyStore.setSSLTrustStore(URL sslTrustStoreUrl, String sslTrustStorePassword, String sslTrustStoreType) Sets the SSL trust store using a URL.setWebClientVersion(BrowserVersion webClientVersion) Sets theBrowserVersionused by the underlying WebClient.Methods inherited from class org.openqa.selenium.remote.AbstractDriverOptions
asMap, getCapabilityNames, setAcceptInsecureCerts, setEnableDownloads, setImplicitWaitTimeout, setPageLoadStrategy, setPageLoadTimeout, setPlatformName, setProxy, setScriptTimeout, setStrictFileInteractability, setUnhandledPromptBehaviourMethods inherited from class org.openqa.selenium.MutableCapabilities
equals, hashCode, merge, setCapability, setCapability, setCapability, toJson, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.openqa.selenium.Capabilities
get, getBrowserName, getPlatformName, is, required
-
Field Details
-
HTMLUNIT_OPTIONS
Key used to store a set of HtmlUnitDriverOptions in aCapabilitiesobject.- See Also:
-
BROWSER_VERSION
Key used to store the browser version in aCapabilitiesobject.This key includes the "garg:" vendor prefix so that the Grid Distributor will ignore it. Using the standard "browserVersion" key instead results in slot match failures, because the distributor requires the version specified in the requested capabilities to match the version specified by the slot stereotype.
- See Also:
-
-
Constructor Details
-
HtmlUnitDriverOptions
public HtmlUnitDriverOptions()Default constructor.Initializes HtmlUnitDriverOptions with default capabilities:
- Browser name set to "htmlunit"
- Home page set to "about:blank"
- Exceptions on failing status codes disabled
- Print content on failing status code disabled
- Use insecure SSL enabled
-
HtmlUnitDriverOptions
Constructs HtmlUnitDriverOptions with a specificBrowserVersion.- Parameters:
version- the browser version to use
-
HtmlUnitDriverOptions
Constructs HtmlUnitDriverOptions with a specificBrowserVersionand JavaScript support enabled/disabled.- Parameters:
version- the browser version to useenableJavascript- true to enable JavaScript support, false to disable
-
HtmlUnitDriverOptions
public HtmlUnitDriverOptions(org.openqa.selenium.Capabilities source) Constructs HtmlUnitDriverOptions from an existingCapabilitiesobject.Transfers mapped capabilities and legacy HtmlUnit options. If the source is another HtmlUnitDriverOptions instance, copies the
WebClientOptionsandBrowserVersionfrom it.- Parameters:
source- source capabilities to copy
-
HtmlUnitDriverOptions
Constructs HtmlUnitDriverOptions from a map of options.- Parameters:
optionsMap- map containing option key-value pairs
-
-
Method Details
-
setBrowserVersion
- Overrides:
setBrowserVersionin classorg.openqa.selenium.remote.AbstractDriverOptions<HtmlUnitDriverOptions>
-
getBrowserVersion
-
getCapability
- Specified by:
getCapabilityin interfaceorg.openqa.selenium.Capabilities- Overrides:
getCapabilityin classorg.openqa.selenium.remote.AbstractDriverOptions<HtmlUnitDriverOptions>
-
setCapability
- Overrides:
setCapabilityin classorg.openqa.selenium.MutableCapabilities
-
getExtraCapabilityNames
- Specified by:
getExtraCapabilityNamesin classorg.openqa.selenium.remote.AbstractDriverOptions<HtmlUnitDriverOptions>
-
getExtraCapability
- Specified by:
getExtraCapabilityin classorg.openqa.selenium.remote.AbstractDriverOptions<HtmlUnitDriverOptions>
-
importOptions
Import values from the specified source into this HtmlUnitDriver options object.- Parameters:
source- sourceWebClientOptionsobject- Returns:
- this
HtmlUnitDriverOptionsobject
-
applyOptions
Apply values from this HtmlUnitDriver options object to the specifies target.- Parameters:
target- targetWebClientOptionsobject
-
isJavaScriptEnabled
public boolean isJavaScriptEnabled()Returns whether JavaScript execution is enabled.- Returns:
trueif JavaScript is enabled;falseotherwise
-
setJavaScriptEnabled
Enables or disables JavaScript execution.- Parameters:
enableJavascript-trueto enable JavaScript;falseto disable it- Returns:
- this options instance
-
isDownloadImages
public boolean isDownloadImages()Returns whether images are downloaded automatically.- Returns:
trueif image downloading is enabled;falseotherwise
-
setDownloadImages
Enables or disables automatic image downloading.- Parameters:
downloadImages-trueto download images;falseotherwise- Returns:
- this options instance
-
getWebClientVersion
Returns the configuredBrowserVersionused by the underlying WebClient.- Returns:
- the current web client browser version
-
setWebClientVersion
Sets theBrowserVersionused by the underlying WebClient.- Parameters:
webClientVersion- the browser version to use- Returns:
- this options instance
- Throws:
NullPointerException- ifwebClientVersionisnull
-
setSSLClientCertificateKeyStore
public HtmlUnitDriverOptions setSSLClientCertificateKeyStore(KeyStore keyStore, char[] keyStorePassword) Sets the SSL client certificate key store from an existingKeyStore.- Parameters:
keyStore- the key store containing the client certificatekeyStorePassword- the password for the key store- Returns:
- this options instance
-
setSSLClientCertificateKeyStore
public HtmlUnitDriverOptions setSSLClientCertificateKeyStore(URL keyStoreUrl, String keyStorePassword, String keyStoreType) Sets the SSL client certificate key store using a URL.- Parameters:
keyStoreUrl- the URL to the key storekeyStorePassword- the key store passwordkeyStoreType- the key store type (e.g.,"PKCS12")- Returns:
- this options instance
- Throws:
NullPointerException- ifkeyStoreUrlisnull
-
setSSLClientCertificateKeyStore
public HtmlUnitDriverOptions setSSLClientCertificateKeyStore(InputStream keyStoreInputStream, String keyStorePassword, String keyStoreType) Sets the SSL client certificate key store from anInputStream.- Parameters:
keyStoreInputStream- the input stream providing the key storekeyStorePassword- the key store passwordkeyStoreType- the key store type (e.g.,"PKCS12")- Returns:
- this options instance
-
setSSLTrustStore
public HtmlUnitDriverOptions setSSLTrustStore(URL sslTrustStoreUrl, String sslTrustStorePassword, String sslTrustStoreType) Sets the SSL trust store using a URL.- Parameters:
sslTrustStoreUrl- the URL to the trust storesslTrustStorePassword- the trust store passwordsslTrustStoreType- the trust store type (e.g.,"JKS")- Returns:
- this options instance
- Throws:
NullPointerException- ifsslTrustStoreUrlisnull
-