public class HtmlUnitDriver extends Object implements org.openqa.selenium.WebDriver, org.openqa.selenium.JavascriptExecutor, org.openqa.selenium.internal.FindsById, org.openqa.selenium.internal.FindsByLinkText, org.openqa.selenium.internal.FindsByXPath, org.openqa.selenium.internal.FindsByName, org.openqa.selenium.internal.FindsByCssSelector, org.openqa.selenium.internal.FindsByTagName, org.openqa.selenium.internal.FindsByClassName, org.openqa.selenium.HasCapabilities, org.openqa.selenium.interactions.HasInputDevices
WebDriver
that drives HtmlUnit,
which is a headless (GUI-less) browser simulator.
The main supported browsers are Chrome, Firefox and Internet Explorer.
Modifier and Type | Class and Description |
---|---|
class |
HtmlUnitDriver.HtmlUnitWindow |
protected static interface |
HtmlUnitDriver.JavaScriptResultsCollection |
org.openqa.selenium.WebDriver.ImeHandler, org.openqa.selenium.WebDriver.Navigation, org.openqa.selenium.WebDriver.Options, org.openqa.selenium.WebDriver.TargetLocator, org.openqa.selenium.WebDriver.Timeouts, org.openqa.selenium.WebDriver.Window
Modifier and Type | Field and Description |
---|---|
static String |
BROWSER_LANGUAGE_CAPABILITY |
static String |
DOWNLOAD_IMAGES_CAPABILITY |
static String |
INVALIDSELECTIONERROR |
static String |
INVALIDXPATHERROR |
static String |
JAVASCRIPT_ENABLED |
Constructor and Description |
---|
HtmlUnitDriver()
Constructs a new instance with JavaScript disabled,
and the
default BrowserVersion. |
HtmlUnitDriver(boolean enableJavascript)
Constructs a new instance, specify JavaScript support
and using the
default BrowserVersion. |
HtmlUnitDriver(com.gargoylesoftware.htmlunit.BrowserVersion version)
Constructs a new instance with the specified
BrowserVersion . |
HtmlUnitDriver(com.gargoylesoftware.htmlunit.BrowserVersion version,
boolean enableJavascript)
Constructs a new instance with the specified
BrowserVersion and the JavaScript support. |
HtmlUnitDriver(org.openqa.selenium.Capabilities capabilities)
The browserName is
BrowserType.HTMLUNIT "htmlunit" and the browserVersion
denotes the required browser AND its version. |
HtmlUnitDriver(org.openqa.selenium.Capabilities desiredCapabilities,
org.openqa.selenium.Capabilities requiredCapabilities) |
Modifier and Type | Method and Description |
---|---|
protected void |
assertElementNotStale(com.gargoylesoftware.htmlunit.html.DomElement element) |
void |
close() |
Object |
executeAsyncScript(String script,
Object... args) |
Object |
executeScript(String script,
Object... args) |
org.openqa.selenium.WebElement |
findElement(org.openqa.selenium.By by) |
org.openqa.selenium.WebElement |
findElementByClassName(String className) |
org.openqa.selenium.WebElement |
findElementByCssSelector(String using) |
org.openqa.selenium.WebElement |
findElementById(String id) |
org.openqa.selenium.WebElement |
findElementByLinkText(String selector) |
org.openqa.selenium.WebElement |
findElementByName(String name) |
org.openqa.selenium.WebElement |
findElementByPartialLinkText(String using) |
org.openqa.selenium.WebElement |
findElementByTagName(String name) |
org.openqa.selenium.WebElement |
findElementByXPath(String selector) |
List<org.openqa.selenium.WebElement> |
findElements(org.openqa.selenium.By by) |
List<org.openqa.selenium.WebElement> |
findElementsByClassName(String className) |
List<org.openqa.selenium.WebElement> |
findElementsByCssSelector(String using) |
List<org.openqa.selenium.WebElement> |
findElementsById(String id) |
List<org.openqa.selenium.WebElement> |
findElementsByLinkText(String selector) |
List<org.openqa.selenium.WebElement> |
findElementsByName(String name) |
List<org.openqa.selenium.WebElement> |
findElementsByPartialLinkText(String using) |
List<org.openqa.selenium.WebElement> |
findElementsByTagName(String name) |
List<org.openqa.selenium.WebElement> |
findElementsByXPath(String selector) |
void |
get(String url) |
protected void |
get(URL fullUrl)
Allows HtmlUnit's about:blank to be loaded in the constructor, and may be useful for other
tests?
|
com.gargoylesoftware.htmlunit.BrowserVersion |
getBrowserVersion()
Get the simulated
BrowserVersion . |
org.openqa.selenium.Capabilities |
getCapabilities() |
String |
getCurrentUrl() |
protected com.gargoylesoftware.htmlunit.WebWindow |
getCurrentWindow() |
HtmlUnitWebElement |
getElementById(int id) |
org.openqa.selenium.interactions.Keyboard |
getKeyboard() |
org.openqa.selenium.interactions.Mouse |
getMouse() |
String |
getPageSource() |
String |
getTitle() |
protected com.gargoylesoftware.htmlunit.WebClient |
getWebClient() |
String |
getWindowHandle() |
Set<String> |
getWindowHandles() |
protected <X> X |
implicitlyWaitFor(Callable<X> condition) |
boolean |
isAcceptSslCertificates() |
boolean |
isDownloadImages() |
boolean |
isJavascriptEnabled() |
protected com.gargoylesoftware.htmlunit.Page |
lastPage() |
org.openqa.selenium.WebDriver.Options |
manage() |
protected com.gargoylesoftware.htmlunit.WebClient |
modifyWebClient(com.gargoylesoftware.htmlunit.WebClient client)
Child classes can override this method to customize the WebClient that the HtmlUnit driver
uses.
|
org.openqa.selenium.WebDriver.Navigation |
navigate() |
protected com.gargoylesoftware.htmlunit.WebClient |
newWebClient(com.gargoylesoftware.htmlunit.BrowserVersion version)
Create the underlying WebClient, but don't set any fields on it.
|
protected void |
pickWindow() |
void |
quit() |
void |
setAcceptSslCertificates(boolean accept) |
void |
setAutoProxy(String autoProxyUrl)
Sets Proxy Autoconfiguration URL for WebClient
|
void |
setDownloadImages(boolean downloadImages) |
void |
setExecutor(Executor executor)
Sets the
Executor to be used for submitting async tasks to. |
void |
setHTTPProxy(String host,
int port,
List<String> noProxyHosts)
Sets HTTP proxy for WebClient with bypass proxy hosts
|
void |
setJavascriptEnabled(boolean enableJavascript) |
void |
setProxy(String host,
int port)
Sets HTTP proxy for WebClient
|
void |
setProxySettings(org.openqa.selenium.Proxy proxy)
Set proxy for WebClient using Proxy.
|
void |
setSocksProxy(String host,
int port)
Sets SOCKS proxy for WebClient
|
void |
setSocksProxy(String host,
int port,
List<String> noProxyHosts)
Sets SOCKS proxy for WebClient with bypass proxy hosts
|
org.openqa.selenium.WebDriver.TargetLocator |
switchTo() |
protected HtmlUnitWebElement |
toWebElement(com.gargoylesoftware.htmlunit.html.DomElement element) |
public static final String INVALIDXPATHERROR
public static final String INVALIDSELECTIONERROR
public static final String BROWSER_LANGUAGE_CAPABILITY
public static final String DOWNLOAD_IMAGES_CAPABILITY
public static final String JAVASCRIPT_ENABLED
public HtmlUnitDriver()
default
BrowserVersion.public HtmlUnitDriver(boolean enableJavascript)
default
BrowserVersion.enableJavascript
- whether to enable JavaScript support or notpublic HtmlUnitDriver(com.gargoylesoftware.htmlunit.BrowserVersion version, boolean enableJavascript)
BrowserVersion
and the JavaScript support.version
- the browser version to useenableJavascript
- whether to enable JavaScript support or notpublic HtmlUnitDriver(com.gargoylesoftware.htmlunit.BrowserVersion version)
BrowserVersion
.version
- the browser version to usepublic HtmlUnitDriver(org.openqa.selenium.Capabilities capabilities)
BrowserType.HTMLUNIT
"htmlunit" and the browserVersion
denotes the required browser AND its version.
For example "chrome" for Chrome, "firefox-45" for Firefox 45
or "internet explorer" for IE.capabilities
- desired capabilities requested for the htmlunit driver sessionpublic HtmlUnitDriver(org.openqa.selenium.Capabilities desiredCapabilities, org.openqa.selenium.Capabilities requiredCapabilities)
public com.gargoylesoftware.htmlunit.BrowserVersion getBrowserVersion()
BrowserVersion
.BrowserVersion
protected com.gargoylesoftware.htmlunit.WebClient newWebClient(com.gargoylesoftware.htmlunit.BrowserVersion version)
version
- Which browser to emulateprotected com.gargoylesoftware.htmlunit.WebClient modifyWebClient(com.gargoylesoftware.htmlunit.WebClient client)
client
- The client to modifypublic void setProxySettings(org.openqa.selenium.Proxy proxy)
proxy
- The proxy preferences.public void setProxy(String host, int port)
host
- The hostname of HTTP proxyport
- The port of HTTP proxy, 0 means HTTP proxy w/o portpublic void setHTTPProxy(String host, int port, List<String> noProxyHosts)
host
- The hostname of HTTP proxyport
- The port of HTTP proxy, 0 means HTTP proxy w/o portnoProxyHosts
- The list of hosts which need to bypass HTTP proxypublic void setSocksProxy(String host, int port)
host
- The hostname of SOCKS proxyport
- The port of SOCKS proxy, 0 means HTTP proxy w/o portpublic void setSocksProxy(String host, int port, List<String> noProxyHosts)
host
- The hostname of SOCKS proxyport
- The port of SOCKS proxy, 0 means HTTP proxy w/o portnoProxyHosts
- The list of hosts which need to bypass SOCKS proxypublic void setExecutor(Executor executor)
Executor
to be used for submitting async tasks to.
You have to close this manually on quit()
executor
- the Executor
to usepublic void setAutoProxy(String autoProxyUrl)
autoProxyUrl
- The Proxy Autoconfiguration URLpublic org.openqa.selenium.Capabilities getCapabilities()
getCapabilities
in interface org.openqa.selenium.HasCapabilities
public void get(String url)
get
in interface org.openqa.selenium.WebDriver
protected void get(URL fullUrl)
fullUrl
- The URL to visitprotected void pickWindow()
public String getCurrentUrl()
getCurrentUrl
in interface org.openqa.selenium.WebDriver
public String getTitle()
getTitle
in interface org.openqa.selenium.WebDriver
public org.openqa.selenium.WebElement findElement(org.openqa.selenium.By by)
findElement
in interface org.openqa.selenium.SearchContext
findElement
in interface org.openqa.selenium.WebDriver
public List<org.openqa.selenium.WebElement> findElements(org.openqa.selenium.By by)
findElements
in interface org.openqa.selenium.SearchContext
findElements
in interface org.openqa.selenium.WebDriver
public String getPageSource()
getPageSource
in interface org.openqa.selenium.WebDriver
public void close()
close
in interface org.openqa.selenium.WebDriver
public void quit()
quit
in interface org.openqa.selenium.WebDriver
public Set<String> getWindowHandles()
getWindowHandles
in interface org.openqa.selenium.WebDriver
public String getWindowHandle()
getWindowHandle
in interface org.openqa.selenium.WebDriver
public Object executeScript(String script, Object... args)
executeScript
in interface org.openqa.selenium.JavascriptExecutor
public Object executeAsyncScript(String script, Object... args)
executeAsyncScript
in interface org.openqa.selenium.JavascriptExecutor
protected void assertElementNotStale(com.gargoylesoftware.htmlunit.html.DomElement element)
public org.openqa.selenium.interactions.Keyboard getKeyboard()
getKeyboard
in interface org.openqa.selenium.interactions.HasInputDevices
public org.openqa.selenium.interactions.Mouse getMouse()
getMouse
in interface org.openqa.selenium.interactions.HasInputDevices
public org.openqa.selenium.WebDriver.TargetLocator switchTo()
switchTo
in interface org.openqa.selenium.WebDriver
public org.openqa.selenium.WebDriver.Navigation navigate()
navigate
in interface org.openqa.selenium.WebDriver
protected com.gargoylesoftware.htmlunit.Page lastPage()
public org.openqa.selenium.WebElement findElementByLinkText(String selector)
findElementByLinkText
in interface org.openqa.selenium.internal.FindsByLinkText
protected HtmlUnitWebElement toWebElement(com.gargoylesoftware.htmlunit.html.DomElement element)
public HtmlUnitWebElement getElementById(int id)
public List<org.openqa.selenium.WebElement> findElementsByLinkText(String selector)
findElementsByLinkText
in interface org.openqa.selenium.internal.FindsByLinkText
public org.openqa.selenium.WebElement findElementById(String id)
findElementById
in interface org.openqa.selenium.internal.FindsById
public List<org.openqa.selenium.WebElement> findElementsById(String id)
findElementsById
in interface org.openqa.selenium.internal.FindsById
public org.openqa.selenium.WebElement findElementByClassName(String className)
findElementByClassName
in interface org.openqa.selenium.internal.FindsByClassName
public List<org.openqa.selenium.WebElement> findElementsByClassName(String className)
findElementsByClassName
in interface org.openqa.selenium.internal.FindsByClassName
public org.openqa.selenium.WebElement findElementByCssSelector(String using)
findElementByCssSelector
in interface org.openqa.selenium.internal.FindsByCssSelector
public List<org.openqa.selenium.WebElement> findElementsByCssSelector(String using)
findElementsByCssSelector
in interface org.openqa.selenium.internal.FindsByCssSelector
public org.openqa.selenium.WebElement findElementByName(String name)
findElementByName
in interface org.openqa.selenium.internal.FindsByName
public List<org.openqa.selenium.WebElement> findElementsByName(String name)
findElementsByName
in interface org.openqa.selenium.internal.FindsByName
public org.openqa.selenium.WebElement findElementByTagName(String name)
findElementByTagName
in interface org.openqa.selenium.internal.FindsByTagName
public List<org.openqa.selenium.WebElement> findElementsByTagName(String name)
findElementsByTagName
in interface org.openqa.selenium.internal.FindsByTagName
public org.openqa.selenium.WebElement findElementByXPath(String selector)
findElementByXPath
in interface org.openqa.selenium.internal.FindsByXPath
public List<org.openqa.selenium.WebElement> findElementsByXPath(String selector)
findElementsByXPath
in interface org.openqa.selenium.internal.FindsByXPath
public boolean isJavascriptEnabled()
public void setJavascriptEnabled(boolean enableJavascript)
public boolean isDownloadImages()
public void setDownloadImages(boolean downloadImages)
public void setAcceptSslCertificates(boolean accept)
public boolean isAcceptSslCertificates()
protected <X> X implicitlyWaitFor(Callable<X> condition)
protected com.gargoylesoftware.htmlunit.WebClient getWebClient()
protected com.gargoylesoftware.htmlunit.WebWindow getCurrentWindow()
public org.openqa.selenium.WebDriver.Options manage()
manage
in interface org.openqa.selenium.WebDriver
public org.openqa.selenium.WebElement findElementByPartialLinkText(String using)
findElementByPartialLinkText
in interface org.openqa.selenium.internal.FindsByLinkText
Copyright © 2021. All rights reserved.