public class HtmlUnitDriver extends Object implements org.openqa.selenium.WebDriver, org.openqa.selenium.JavascriptExecutor, org.openqa.selenium.HasCapabilities, org.openqa.selenium.interactions.Interactive
WebDriver that drives
HtmlUnit, which is a headless
(GUI-less) browser simulator.
The main supported browsers are Chrome, Edge, Firefox and Internet Explorer.
| Modifier and Type | Class and Description |
|---|---|
protected static class |
HtmlUnitDriver.ElementsMap |
protected static interface |
HtmlUnitDriver.JavaScriptResultsCollection |
| Modifier and Type | Field and Description |
|---|---|
static String |
BROWSER_LANGUAGE_CAPABILITY
BROWSER_LANGUAGE_CAPABILITY = "browserLanguage".
|
static String |
DOWNLOAD_IMAGES_CAPABILITY
DOWNLOAD_IMAGES_CAPABILITY = "downloadImages".
|
static String |
JAVASCRIPT_ENABLED
JAVASCRIPT_ENABLED = "javascriptEnabled".
|
| 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(BrowserVersion version)
Constructs a new instance with the specified
BrowserVersion. |
HtmlUnitDriver(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
Browser.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(DomElement element) |
void |
click(DomElement element,
boolean directClick) |
void |
close() |
void |
doubleClick(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() |
BrowserVersion |
getBrowserVersion()
Get the simulated
BrowserVersion. |
org.openqa.selenium.Capabilities |
getCapabilities() |
String |
getCurrentUrl() |
HtmlUnitWindow |
getCurrentWindow() |
HtmlUnitDriver.ElementsMap |
getElementsMap() |
HtmlUnitKeyboard |
getKeyboard() |
HtmlUnitMouse |
getMouse() |
String |
getPageSource() |
String |
getTitle() |
WebClient |
getWebClient() |
String |
getWindowHandle() |
Set<String> |
getWindowHandles() |
protected <X> X |
implicitlyWaitFor(Callable<X> condition) |
boolean |
isAcceptInsecureCerts() |
boolean |
isDownloadImages() |
boolean |
isJavascriptEnabled() |
org.openqa.selenium.WebDriver.Options |
manage() |
protected WebClient |
modifyWebClient(WebClient client)
Child classes can override this method to customize the WebClient that the
HtmlUnit driver uses.
|
void |
mouseDown(DomElement element) |
void |
mouseMove(DomElement element) |
void |
mouseUp(DomElement element) |
org.openqa.selenium.WebDriver.Navigation |
navigate() |
protected WebClient |
newWebClient(BrowserVersion version)
Create the underlying WebClient, but don't set any fields on it.
|
void |
openNewWindow() |
void |
perform(Collection<org.openqa.selenium.interactions.Sequence> sequences) |
void |
quit() |
void |
resetInputState() |
protected void |
runAsync(Runnable r) |
void |
sendKeys(HtmlUnitWebElement element,
CharSequence... value) |
void |
setAcceptInsecureCerts(boolean accept) |
void |
setAutoProxy(String autoProxyUrl)
Sets Proxy Autoconfiguration URL for WebClient.
|
void |
setCurrentWindow(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 void |
switchToDefaultContentOfWindow(WebWindow window) |
protected HtmlUnitWebElement |
toWebElement(DomElement element) |
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(BrowserVersion version)
BrowserVersion.version - the browser version to usepublic HtmlUnitDriver(boolean enableJavascript)
default BrowserVersion.enableJavascript - whether to enable JavaScript support or notpublic HtmlUnitDriver(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)
Browser.HTMLUNIT "htmlunit" and the
browserVersion denotes the required browser AND its version. For example
"chrome" for Chrome, "firefox-100" for Firefox 100 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(DomElement element, boolean directClick)
public void doubleClick(DomElement element)
public void mouseUp(DomElement element)
public void mouseMove(DomElement element)
public void mouseDown(DomElement element)
public void submit(HtmlUnitWebElement element)
public void sendKeys(HtmlUnitWebElement element, CharSequence... value)
public BrowserVersion getBrowserVersion()
BrowserVersion.BrowserVersionprotected WebClient newWebClient(BrowserVersion version)
version - Which browser to emulateprotected WebClient modifyWebClient(WebClient client)
client - The client to modifypublic HtmlUnitAlert getAlert()
public HtmlUnitDriver.ElementsMap getElementsMap()
public void setCurrentWindow(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(DomElement element)
public HtmlUnitKeyboard getKeyboard()
public HtmlUnitMouse getMouse()
public 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(DomElement element)
public boolean isJavascriptEnabled()
public void setJavascriptEnabled(boolean enableJavascript)
public boolean isDownloadImages()
public void setDownloadImages(boolean downloadImages)
public void setAcceptInsecureCerts(boolean accept)
public boolean isAcceptInsecureCerts()
protected <X> X implicitlyWaitFor(Callable<X> condition)
public WebClient getWebClient()
public HtmlUnitWindow getCurrentWindow()
public org.openqa.selenium.WebDriver.Options manage()
manage in interface org.openqa.selenium.WebDriverpublic void perform(Collection<org.openqa.selenium.interactions.Sequence> sequences)
perform in interface org.openqa.selenium.interactions.Interactivepublic void resetInputState()
resetInputState in interface org.openqa.selenium.interactions.Interactiveprotected void switchToDefaultContentOfWindow(WebWindow window)
public void openNewWindow()
Copyright © 2023. All rights reserved.