public class HtmlUnitDriver extends Object implements org.openqa.selenium.WebDriver, org.openqa.selenium.JavascriptExecutor, 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 |
|---|---|
protected static class |
HtmlUnitDriver.ElementsMap |
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 |
click(com.gargoylesoftware.htmlunit.html.DomElement element,
boolean directClick) |
void |
close() |
void |
doubleClick(com.gargoylesoftware.htmlunit.html.DomElement element) |
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 |
findElement(HtmlUnitWebElement element,
org.openqa.selenium.By by) |
List<org.openqa.selenium.WebElement> |
findElements(org.openqa.selenium.By by) |
List<org.openqa.selenium.WebElement> |
findElements(HtmlUnitWebElement element,
org.openqa.selenium.By by) |
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?
|
HtmlUnitAlert |
getAlert() |
com.gargoylesoftware.htmlunit.BrowserVersion |
getBrowserVersion()
Get the simulated
BrowserVersion. |
org.openqa.selenium.Capabilities |
getCapabilities() |
String |
getCurrentUrl() |
protected com.gargoylesoftware.htmlunit.WebWindow |
getCurrentWindow() |
HtmlUnitDriver.ElementsMap |
getElementsMap() |
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() |
HtmlUnitWindow |
getWindowManager() |
protected <X> X |
implicitlyWaitFor(Callable<X> condition) |
boolean |
isAcceptSslCertificates() |
boolean |
isDownloadImages() |
boolean |
isJavascriptEnabled() |
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.
|
void |
mouseDown(com.gargoylesoftware.htmlunit.html.DomElement element) |
void |
mouseMove(com.gargoylesoftware.htmlunit.html.DomElement element) |
void |
mouseUp(com.gargoylesoftware.htmlunit.html.DomElement element) |
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.
|
void |
quit() |
protected void |
runAsync(Runnable r) |
void |
sendKeys(HtmlUnitWebElement element,
CharSequence... value) |
void |
setAcceptSslCertificates(boolean accept) |
void |
setAutoProxy(String autoProxyUrl)
Sets Proxy Autoconfiguration URL for WebClient
|
void |
setCurrentWindow(com.gargoylesoftware.htmlunit.WebWindow window) |
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
|
void |
submit(HtmlUnitWebElement element) |
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(com.gargoylesoftware.htmlunit.BrowserVersion version)
BrowserVersion.version - the browser version to usepublic 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(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)
protected void runAsync(Runnable r)
public void click(com.gargoylesoftware.htmlunit.html.DomElement element,
boolean directClick)
public void doubleClick(com.gargoylesoftware.htmlunit.html.DomElement element)
public void mouseUp(com.gargoylesoftware.htmlunit.html.DomElement element)
public void mouseMove(com.gargoylesoftware.htmlunit.html.DomElement element)
public void mouseDown(com.gargoylesoftware.htmlunit.html.DomElement element)
public void submit(HtmlUnitWebElement element)
public void sendKeys(HtmlUnitWebElement element, CharSequence... value)
public com.gargoylesoftware.htmlunit.BrowserVersion getBrowserVersion()
BrowserVersion.BrowserVersionprotected 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 HtmlUnitWindow getWindowManager()
public HtmlUnitAlert getAlert()
public HtmlUnitDriver.ElementsMap getElementsMap()
public void setCurrentWindow(com.gargoylesoftware.htmlunit.WebWindow window)
public 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.HasCapabilitiespublic void get(String url)
get in interface org.openqa.selenium.WebDriverprotected void get(URL fullUrl)
fullUrl - The URL to visitpublic String getCurrentUrl()
getCurrentUrl in interface org.openqa.selenium.WebDriverpublic String getTitle()
getTitle in interface org.openqa.selenium.WebDriverpublic org.openqa.selenium.WebElement findElement(org.openqa.selenium.By by)
findElement in interface org.openqa.selenium.SearchContextfindElement in interface org.openqa.selenium.WebDriverpublic List<org.openqa.selenium.WebElement> findElements(org.openqa.selenium.By by)
findElements in interface org.openqa.selenium.SearchContextfindElements in interface org.openqa.selenium.WebDriverpublic org.openqa.selenium.WebElement findElement(HtmlUnitWebElement element, org.openqa.selenium.By by)
public List<org.openqa.selenium.WebElement> findElements(HtmlUnitWebElement element, org.openqa.selenium.By by)
public String getPageSource()
getPageSource in interface org.openqa.selenium.WebDriverpublic void close()
close in interface org.openqa.selenium.WebDriverpublic void quit()
quit in interface org.openqa.selenium.WebDriverpublic Set<String> getWindowHandles()
getWindowHandles in interface org.openqa.selenium.WebDriverpublic String getWindowHandle()
getWindowHandle in interface org.openqa.selenium.WebDriverpublic Object executeScript(String script, Object... args)
executeScript in interface org.openqa.selenium.JavascriptExecutorpublic Object executeAsyncScript(String script, Object... args)
executeAsyncScript in interface org.openqa.selenium.JavascriptExecutorprotected void assertElementNotStale(com.gargoylesoftware.htmlunit.html.DomElement element)
public org.openqa.selenium.interactions.Keyboard getKeyboard()
getKeyboard in interface org.openqa.selenium.interactions.HasInputDevicespublic org.openqa.selenium.interactions.Mouse getMouse()
getMouse in interface org.openqa.selenium.interactions.HasInputDevicespublic org.openqa.selenium.WebDriver.TargetLocator switchTo()
switchTo in interface org.openqa.selenium.WebDriverpublic org.openqa.selenium.WebDriver.Navigation navigate()
navigate in interface org.openqa.selenium.WebDriverprotected HtmlUnitWebElement toWebElement(com.gargoylesoftware.htmlunit.html.DomElement element)
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.WebDriverCopyright © 2022. All rights reserved.