public class WebClient extends Object implements Serializable, AutoCloseable
A standard usage of HtmlUnit will start with using the getPage(String) method
(or getPage(URL)) to load a first Page
and will continue with further processing on this page depending on its type.
final WebClient webClient = new WebClient();
final HtmlPage startPage = webClient.getPage("http://htmlunit.sf.net");
assertEquals("HtmlUnit - Welcome to HtmlUnit", startPage.getTitleText());
Note: a WebClient instance is not thread safe. It is intended to be used from a single thread.
| Modifier and Type | Class and Description |
|---|---|
static class |
WebClient.PooledCSS3Parser
This is a poolable CSS3Parser which can be reused automatically when closed.
|
| Modifier and Type | Field and Description |
|---|---|
static String |
TARGET_BLANK
target "_blank".
|
static String |
TARGET_SELF
target "_self".
|
| Constructor and Description |
|---|
WebClient()
Creates a web client instance using the browser version returned by
BrowserVersion.getDefault(). |
WebClient(BrowserVersion browserVersion)
Creates a web client instance using the specified
BrowserVersion. |
WebClient(BrowserVersion browserVersion,
boolean javaScriptEngineEnabled,
String proxyHost,
int proxyPort)
Creates an instance that will use the specified
BrowserVersion and proxy server. |
WebClient(BrowserVersion browserVersion,
boolean javaScriptEngineEnabled,
String proxyHost,
int proxyPort,
String proxyScheme)
Creates an instance that will use the specified
BrowserVersion and proxy server. |
WebClient(BrowserVersion browserVersion,
String proxyHost,
int proxyPort)
Creates an instance that will use the specified
BrowserVersion and proxy server. |
WebClient(BrowserVersion browserVersion,
String proxyHost,
int proxyPort,
String proxyScheme)
Creates an instance that will use the specified
BrowserVersion and proxy server. |
| Modifier and Type | Method and Description |
|---|---|
void |
addCookie(String cookieString,
URL pageUrl,
Object origin)
Parses the given cookie and adds this to our cookie store.
|
void |
addRequestHeader(String name,
String value)
Adds a header which will be sent with EVERY request from this client.
|
void |
addWebWindowListener(WebWindowListener listener)
Adds a listener for
WebWindowEvents. |
WebSocketAdapter |
buildWebSocketAdapter(WebSocketListener webSocketListener)
Creates a new
WebSocketAdapter. |
void |
close()
Closes all opened windows, stopping all background JavaScript processing.
|
boolean |
containsWebWindow(WebWindow webWindow)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
|
void |
deregisterWebWindow(WebWindow webWindow)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
|
void |
download(WebWindow requestingWindow,
String target,
WebRequest request,
boolean checkHash,
String forceAttachmentWithFilename,
String description)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
|
static URL |
expandUrl(URL baseUrl,
String relativeUrl)
Expands a relative URL relative to the specified base.
|
AjaxController |
getAjaxController()
Gets the current AJAX controller.
|
AlertHandler |
getAlertHandler()
Returns the alert handler for this webclient.
|
AttachmentHandler |
getAttachmentHandler()
Returns the current attachment handler.
|
Set<BroadcastChannel> |
getBroadcastChannels()
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
|
BrowserVersion |
getBrowserVersion()
Returns the current browser version.
|
Cache |
getCache()
Gets the cache currently being used.
|
ClipboardHandler |
getClipboardHandler()
Returns the current clipboard handler.
|
ConfirmHandler |
getConfirmHandler()
Returns the confirm handler.
|
CookieManager |
getCookieManager()
Returns the cookie manager used by this web client.
|
Set<Cookie> |
getCookies(URL url)
Returns the currently configured cookies applicable to the specified URL, in an unmodifiable set.
|
org.apache.http.client.CredentialsProvider |
getCredentialsProvider()
Returns the credentials provider for this client instance.
|
WebClient.PooledCSS3Parser |
getCSS3Parser()
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
|
org.htmlunit.cssparser.parser.CSSErrorHandler |
getCssErrorHandler()
Returns the CSS error handler used by this web client when CSS problems are encountered.
|
WebWindow |
getCurrentWindow()
Returns the "current" window for this client.
|
Executor |
getExecutor()
Returns the executor for this
WebClient. |
FrameContentHandler |
getFrameContentHandler()
Returns the current FrameContent handler.
|
HTMLParserListener |
getHTMLParserListener()
Gets the configured listener for messages generated by the HTML parser.
|
IncorrectnessListener |
getIncorrectnessListener()
Gets the current listener for encountered incorrectness (except HTML parsing messages that
are handled by the HTML parser listener).
|
AbstractJavaScriptEngine<?> |
getJavaScriptEngine()
This method is intended for testing only - use at your own risk.
|
JavaScriptErrorListener |
getJavaScriptErrorListener()
Returns the javascript error listener for this
WebClient. |
long |
getJavaScriptTimeout()
Returns the number of milliseconds that a script is allowed to execute before being terminated.
|
OnbeforeunloadHandler |
getOnbeforeunloadHandler()
Returns the onbeforeunload handler for this
WebClient. |
WebClientOptions |
getOptions()
Returns the options object of this WebClient.
|
<P extends Page> |
getPage(String url)
Convenient method to build a URL and load it into the current WebWindow as it would be done
by
getPage(WebWindow, WebRequest). |
<P extends Page> |
|