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
WebWindowEvent s. |
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,
boolean forceLoad,
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.
|
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> |
getPage(URL url)
Convenient method to load a URL into the current top WebWindow as it would be done
by
getPage(WebWindow, WebRequest) . |
<P extends Page> |
getPage(WebRequest request)
Convenient method to load a web request into the current top WebWindow.
|
<P extends Page> |
getPage(WebWindow webWindow,
WebRequest webRequest)
Send a request to a server and return a Page that represents the
response from the server.
|
PageCreator |
getPageCreator()
Returns the current page creator.
|
PrintHandler |
getPrintHandler()
Returns the current
PrintHandler . |
PromptHandler |
getPromptHandler()
Returns the prompt handler.
|
RefreshHandler |
getRefreshHandler()
Returns the current refresh handler.
|
ScriptPreProcessor |
getScriptPreProcessor()
Returns the script pre processor for this
WebClient . |
StatusHandler |
getStatusHandler()
Returns the status handler for this
WebClient . |
StorageHolder |
getStorageHolder()
Gets the holder for the different storages.
|
List<TopLevelWindow> |
getTopLevelWindows()
Returns an immutable list of open top level windows.
|
WebConnection |
getWebConnection()
Returns the object that will resolve all URL requests.
|
WebConsole |
getWebConsole()
Returns the WebConsole.
|
WebStartHandler |
getWebStartHandler()
Returns the current WebStart handler.
|
WebWindow |
getWebWindowByName(String name)
Returns the first
WebWindow that matches the specified name. |
List<WebWindow> |
getWebWindows()
Returns an immutable list of open web windows (whether they are top level windows or not).
|
String |
guessContentType(File file)
Tries to guess the content type of the file.
|
void |
initialize(WebWindow webWindow,
Page page)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
|
void |
initializeEmptyWindow(WebWindow webWindow,
Page page)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
|
boolean |
isJavaScriptEnabled()
Returns true if the javaScript support is enabled.
|
boolean |
isJavaScriptEngineEnabled()
Returns true if the javaScript engine is enabled.
|
void |
loadDownloadedResponses()
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
|
HtmlPage |
loadHtmlCodeIntoCurrentWindow(String htmlCode)
Parses the given XHtml code string and loads the resulting XHtmlPage into
the current window.
|
WebResponse |
loadWebResponse(WebRequest webRequest)
Loads a
WebResponse from the server. |
Page |
loadWebResponseInto(WebResponse webResponse,
WebWindow webWindow)
Creates a page based on the specified response and inserts it into the specified window.
|
Page |
loadWebResponseInto(WebResponse webResponse,
WebWindow webWindow,
String forceAttachmentWithFilename)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
|
XHtmlPage |
loadXHtmlCodeIntoCurrentWindow(String xhtmlCode)
Parses the given XHtml code string and loads the resulting XHtmlPage into
the current window.
|
DialogWindow |
openDialogWindow(URL url,
WebWindow opener,
Object dialogArguments)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
|
WebWindow |
openTargetWindow(WebWindow opener,
String windowName,
String defaultName)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
|
WebWindow |
openWindow(URL url,
String windowName)
Open a new window with the specified name.
|
WebWindow |
openWindow(URL url,
String windowName,
WebWindow opener)
Open a new window with the specified name.
|
void |
printContentIfNecessary(WebResponse webResponse)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
|
void |
registerWebWindow(WebWindow webWindow)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
|
void |
removeRequestHeader(String name)
Removes a header from being sent with EVERY request from this client.
|
void |
removeWebWindowListener(WebWindowListener listener)
Removes a listener for
WebWindowEvent s. |
void |
reset()
Experimental API: May be changed in next release
and may not yet work perfectly!
|
void |
setAjaxController(AjaxController newValue)
Sets the current AJAX controller.
|
void |
setAlertHandler(AlertHandler alertHandler)
Sets the alert handler for this webclient.
|
void |
setAttachmentHandler(AttachmentHandler handler)
Sets the attachment handler.
|
void |
setCache(Cache cache)
Sets the cache to use.
|
void |
setClipboardHandler(ClipboardHandler handler)
Sets the clipboard handler.
|
void |
setConfirmHandler(ConfirmHandler handler)
Sets the handler that will be executed when the JavaScript method Window.confirm() is called.
|
void |
setCookieManager(CookieManager cookieManager)
Sets the cookie manager used by this web client.
|
void |
setCredentialsProvider(org.apache.http.client.CredentialsProvider credentialsProvider)
Sets the credentials provider that will provide authentication information when
trying to access protected information on a web server.
|
void |
setCssErrorHandler(org.htmlunit.cssparser.parser.CSSErrorHandler cssErrorHandler)
Sets the CSS error handler used by this web client when CSS problems are encountered.
|
void |
setCurrentWindow(WebWindow window)
Sets the "current" window for this client.
|
void |
setExecutor(ExecutorService executor)
Changes the ExecutorService for this
WebClient . |
void |
setFrameContentHandler(FrameContentHandler handler)
Sets the FrameContent handler.
|
void |
setHTMLParserListener(HTMLParserListener listener)
Sets the listener for messages generated by the HTML parser.
|
void |
setIncorrectnessListener(IncorrectnessListener listener)
Returns the current HTML incorrectness listener.
|
void |
setJavaScriptEngine(AbstractJavaScriptEngine<?> engine)
This method is intended for testing only - use at your own risk.
|
void |
setJavaScriptErrorListener(JavaScriptErrorListener javaScriptErrorListener)
Sets the javascript error listener for this
WebClient . |
void |
setJavaScriptTimeout(long timeout)
Sets the number of milliseconds that a script is allowed to execute before being terminated.
|
void |
setOnbeforeunloadHandler(OnbeforeunloadHandler onbeforeunloadHandler)
Sets the onbeforeunload handler for this
WebClient . |
void |
setPageCreator(PageCreator pageCreator)
Sets the object that will be used to create pages.
|
void |
setPrintHandler(PrintHandler handler)
Sets the
PrintHandler to be used if Windoe.print() is called
(Printing Spec). |
void |
setPromptHandler(PromptHandler handler)
Sets the handler that will be executed when the JavaScript method Window.prompt() is called.
|
void |
setRefreshHandler(RefreshHandler handler)
Sets the handler to be used whenever a refresh is triggered.
|
void |
setScriptPreProcessor(ScriptPreProcessor scriptPreProcessor)
Sets the script pre processor for this
WebClient . |
void |
setStatusHandler(StatusHandler statusHandler)
Sets the status handler for this webclient.
|
void |
setWebConnection(WebConnection webConnection)
Sets the object that will resolve all URL requests.
|
void |
setWebStartHandler(WebStartHandler handler)
Sets the WebStart handler.
|
void |
throwFailingHttpStatusCodeExceptionIfNecessary(WebResponse webResponse)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
|
int |
waitForBackgroundJavaScript(long timeoutMillis)
Experimental API: May be changed in next release
and may not yet work perfectly!
|
int |
waitForBackgroundJavaScriptStartingBefore(long delayMillis)
Experimental API: May be changed in next release
and may not yet work perfectly!
|
public static final String TARGET_BLANK
public static final String TARGET_SELF
public WebClient()
BrowserVersion.getDefault()
.public WebClient(BrowserVersion browserVersion)
BrowserVersion
.browserVersion
- the browser version to simulatepublic WebClient(BrowserVersion browserVersion, String proxyHost, int proxyPort)
BrowserVersion
and proxy server.browserVersion
- the browser version to simulateproxyHost
- the server that will act as proxy or null for no proxyproxyPort
- the port to use on the proxy serverpublic WebClient(BrowserVersion browserVersion, String proxyHost, int proxyPort, String proxyScheme)
BrowserVersion
and proxy server.browserVersion
- the browser version to simulateproxyHost
- the server that will act as proxy or null for no proxyproxyPort
- the port to use on the proxy serverproxyScheme
- the scheme http/httpspublic WebClient(BrowserVersion browserVersion, boolean javaScriptEngineEnabled, String proxyHost, int proxyPort)
BrowserVersion
and proxy server.browserVersion
- the browser version to simulatejavaScriptEngineEnabled
- set to false if the simulated browser should not support javaScriptproxyHost
- the server that will act as proxy or null for no proxyproxyPort
- the port to use on the proxy serverpublic WebClient(BrowserVersion browserVersion, boolean javaScriptEngineEnabled, String proxyHost, int proxyPort, String proxyScheme)
BrowserVersion
and proxy server.browserVersion
- the browser version to simulatejavaScriptEngineEnabled
- set to false if the simulated browser should not support javaScriptproxyHost
- the server that will act as proxy or null for no proxyproxyPort
- the port to use on the proxy serverproxyScheme
- the scheme http/httpspublic WebConnection getWebConnection()
public void setWebConnection(WebConnection webConnection)
webConnection
- the new web connectionpublic <P extends Page> P getPage(WebWindow webWindow, WebRequest webRequest) throws IOException, FailingHttpStatusCodeException
The returned Page
will be created by the PageCreator
configured by setPageCreator(PageCreator)
, if any.
The DefaultPageCreator
will create a Page
depending on the content type of the HTTP response,
basically HtmlPage
for HTML content, XmlPage
for XML content,
TextPage
for other text content and UnexpectedPage
for anything else.
P
- the page typewebWindow
- the WebWindow to load the result of the request intowebRequest
- the web requestIOException
- if an IO error occursFailingHttpStatusCodeException
- if the server returns a failing status code AND the property
WebClientOptions.setThrowExceptionOnFailingStatusCode(boolean)
is set to trueWebRequest
public <P extends Page> P getPage(String url) throws IOException, FailingHttpStatusCodeException, MalformedURLException
getPage(WebWindow, WebRequest)
.P
- the page typeurl
- the URL of the new contentFailingHttpStatusCodeException
- if the server returns a failing status code AND the property
WebClientOptions.setThrowExceptionOnFailingStatusCode(boolean)
is set to true.IOException
- if an IO problem occursMalformedURLException
- if no URL can be created from the provided stringpublic <P extends Page> P getPage(URL url) throws IOException, FailingHttpStatusCodeException
getPage(WebWindow, WebRequest)
.P
- the page typeurl
- the URL of the new contentFailingHttpStatusCodeException
- if the server returns a failing status code AND the property
WebClientOptions.setThrowExceptionOnFailingStatusCode(boolean)
is set to true.IOException
- if an IO problem occurspublic <P extends Page> P getPage(WebRequest request) throws IOException, FailingHttpStatusCodeException
P
- the page typerequest
- the request parametersFailingHttpStatusCodeException
- if the server returns a failing status code AND the property
WebClientOptions.setThrowExceptionOnFailingStatusCode(boolean)
is set to true.IOException
- if an IO problem occursgetPage(WebWindow,WebRequest)
public Page loadWebResponseInto(WebResponse webResponse, WebWindow webWindow) throws IOException, FailingHttpStatusCodeException
Creates a page based on the specified response and inserts it into the specified window. All page initialization and event notification is handled here.
Note that if the page created is an attachment page, and an AttachmentHandler
has been
registered with this client, the page is not loaded into the specified window; in this case,
the page is loaded into a new window, and attachment handling is delegated to the registered
AttachmentHandler
.
webResponse
- the response that will be used to create the new pagewebWindow
- the window that the new page will be placed withinIOException
- if an IO error occursFailingHttpStatusCodeException
- if the server returns a failing status code AND the property
WebClientOptions.setThrowExceptionOnFailingStatusCode(boolean)
is set to truesetAttachmentHandler(AttachmentHandler)
public Page loadWebResponseInto(WebResponse webResponse, WebWindow webWindow, String forceAttachmentWithFilename) throws IOException, FailingHttpStatusCodeException
Creates a page based on the specified response and inserts it into the specified window. All page initialization and event notification is handled here.
Note that if the page created is an attachment page, and an AttachmentHandler
has been
registered with this client, the page is not loaded into the specified window; in this case,
the page is loaded into a new window, and attachment handling is delegated to the registered
AttachmentHandler
.
webResponse
- the response that will be used to create the new pagewebWindow
- the window that the new page will be placed withinforceAttachmentWithFilename
- if not null
, handle this as an attachment with the specified name
or if an empty string ("") use the filename provided in the responseIOException
- if an IO error occursFailingHttpStatusCodeException
- if the server returns a failing status code AND the property
WebClientOptions.setThrowExceptionOnFailingStatusCode(boolean)
is set to truesetAttachmentHandler(AttachmentHandler)
public void printContentIfNecessary(WebResponse webResponse)
Logs the response's content if its status code indicates a request failure and
WebClientOptions.isPrintContentOnFailingStatusCode()
returns true
.
webResponse
- the response whose content may be loggedpublic void throwFailingHttpStatusCodeExceptionIfNecessary(WebResponse webResponse)
Throws a FailingHttpStatusCodeException
if the request's status code indicates a request
failure and WebClientOptions.isThrowExceptionOnFailingStatusCode()
returns true
.
webResponse
- the response which may trigger a FailingHttpStatusCodeException
public void addRequestHeader(String name, String value)
name
- the name of the header to addvalue
- the value of the header to addremoveRequestHeader(String)
public void removeRequestHeader(String name)
addRequestHeader(String, String)
before.name
- the name of the header to removeaddRequestHeader(java.lang.String, java.lang.String)
public void setCredentialsProvider(org.apache.http.client.CredentialsProvider credentialsProvider)
credentialsProvider
- the new credentials provider to use to authenticatepublic org.apache.http.client.CredentialsProvider getCredentialsProvider()
DefaultCredentialsProvider
.public AbstractJavaScriptEngine<?> getJavaScriptEngine()
null
)public void setJavaScriptEngine(AbstractJavaScriptEngine<?> engine)
engine
- the new script engine to usepublic CookieManager getCookieManager()
public void setCookieManager(CookieManager cookieManager)
cookieManager
- the cookie manager used by this web clientpublic void setAlertHandler(AlertHandler alertHandler)
alertHandler
- the new alerthandler or null if none is specifiedpublic AlertHandler getAlertHandler()
public void setConfirmHandler(ConfirmHandler handler)
handler
- the new handler or null if no handler is to be usedpublic ConfirmHandler getConfirmHandler()
public void setPromptHandler(PromptHandler handler)
handler
- the new handler or null if no handler is to be usedpublic PromptHandler getPromptHandler()
public void setStatusHandler(StatusHandler statusHandler)
statusHandler
- the new status handler or null if none is specifiedpublic StatusHandler getStatusHandler()
WebClient
.public Executor getExecutor()
WebClient
.public void setExecutor(ExecutorService executor)
WebClient
.
You have to call this before the first use of the executor, otherwise
an IllegalStateExceptions is thrown.executor
- the new Executor.public void setJavaScriptErrorListener(JavaScriptErrorListener javaScriptErrorListener)
WebClient
.
When setting to null, the DefaultJavaScriptErrorListener
is used.javaScriptErrorListener
- the new JavaScriptErrorListener or null if none is specifiedpublic JavaScriptErrorListener getJavaScriptErrorListener()
WebClient
.public BrowserVersion getBrowserVersion()
public WebWindow getCurrentWindow()
getPage(...)
is called without specifying a window.public void setCurrentWindow(WebWindow window)
getPage(...)
is called without specifying a window.window
- the new "current" window for this clientpublic void addWebWindowListener(WebWindowListener listener)
WebWindowEvent
s. All events from all windows associated with this
client will be sent to the specified listener.listener
- a listenerpublic void removeWebWindowListener(WebWindowListener listener)
WebWindowEvent
s.listener
- a listenerpublic WebWindow openWindow(URL url, String windowName)
url
- the URL to load content from or null if no content is to be loadedwindowName
- the name of the new windowpublic WebWindow openWindow(URL url, String windowName, WebWindow opener)
url
- the URL to load content from or null if no content is to be loadedwindowName
- the name of the new windowopener
- the web window that is calling openWindowpublic WebWindow openTargetWindow(WebWindow opener, String windowName, String defaultName)
opener
- the web window that is calling openWindowwindowName
- the name of the new windowdefaultName
- the default target if no name is givenpublic DialogWindow openDialogWindow(URL url, WebWindow opener, Object dialogArguments) throws IOException
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Opens a new dialog window.url
- the URL of the document to load and displayopener
- the web window that is opening the dialogdialogArguments
- the object to make available inside the dialog via window.dialogArguments
IOException
- if there is an IO errorpublic void setPageCreator(PageCreator pageCreator)
pageCreator
- the new page creatorpublic PageCreator getPageCreator()
public WebWindow getWebWindowByName(String name) throws WebWindowNotFoundException
WebWindow
that matches the specified name.name
- the name to search forWebWindow
with the specified nameWebWindowNotFoundException
- if the WebWindow
can't be foundgetWebWindows()
,
getTopLevelWindows()
public void initialize(WebWindow webWindow, Page page)
webWindow
- the new WebWindowpage
- the page that will become the enclosing pagepublic void initializeEmptyWindow(WebWindow webWindow, Page page)
webWindow
- the new WebWindowpage
- the page that will become the enclosing pagepublic void registerWebWindow(WebWindow webWindow)
webWindow
- the new WebWindowpublic void deregisterWebWindow(WebWindow webWindow)
webWindow
- the window to removepublic static URL expandUrl(URL baseUrl, String relativeUrl) throws MalformedURLException
new URL(baseUrl, relativeUrl)
but
there are some cases that URL doesn't handle correctly. See
RFC1808
regarding Relative Uniform Resource Locators for more information.baseUrl
- the base URLrelativeUrl
- the relative URLMalformedURLException
- if an error occurred when creating a URL objectpublic String guessContentType(File file)
file
- the filepublic WebResponse loadWebResponse(WebRequest webRequest) throws IOException
WebResponse
from the server.webRequest
- the requestIOException
- if an IO problem occurspublic List<WebWindow> getWebWindows()
The list is ordered by age, the oldest one first.
getWebWindowByName(String)
,
getTopLevelWindows()
public boolean containsWebWindow(WebWindow webWindow)
webWindow
- the window to checkpublic List<TopLevelWindow> getTopLevelWindows()
The list is ordered by age, the oldest one first.
getWebWindowByName(String)
,
getWebWindows()
public void setRefreshHandler(RefreshHandler handler)
RefreshHandler
for more details.handler
- the new handlerpublic RefreshHandler getRefreshHandler()
NiceRefreshHandler(2)
.public void setScriptPreProcessor(ScriptPreProcessor scriptPreProcessor)
WebClient
.scriptPreProcessor
- the new preprocessor or null if none is specifiedpublic ScriptPreProcessor getScriptPreProcessor()
WebClient
.public void setHTMLParserListener(HTMLParserListener listener)
listener
- the new listener, null
if messages should be totally ignoredpublic HTMLParserListener getHTMLParserListener()
null
if no listener is defined (default value)public org.htmlunit.cssparser.parser.CSSErrorHandler getCssErrorHandler()
DefaultCssErrorHandler
,
SilentCssErrorHandler
public void setCssErrorHandler(org.htmlunit.cssparser.parser.CSSErrorHandler cssErrorHandler)
cssErrorHandler
- the CSS error handler used by this web client when CSS problems are encounteredDefaultCssErrorHandler
,
SilentCssErrorHandler
public void setJavaScriptTimeout(long timeout)
timeout
- the timeout value, in millisecondspublic long getJavaScriptTimeout()
public IncorrectnessListener getIncorrectnessListener()
IncorrectnessListenerImpl
.null
)public void setIncorrectnessListener(IncorrectnessListener listener)
listener
- the new value (not null
)public WebConsole getWebConsole()
public AjaxController getAjaxController()
public void setAjaxController(AjaxController newValue)
newValue
- the controllerpublic void setAttachmentHandler(AttachmentHandler handler)
handler
- the new attachment handlerpublic AttachmentHandler getAttachmentHandler()
public void setWebStartHandler(WebStartHandler handler)
handler
- the new WebStart handlerpublic WebStartHandler getWebStartHandler()
public ClipboardHandler getClipboardHandler()
public void setClipboardHandler(ClipboardHandler handler)
handler
- the new clipboard handlerpublic PrintHandler getPrintHandler()
PrintHandler
.PrintHandler
or null if print
requests are ignoredpublic void setPrintHandler(PrintHandler handler)
PrintHandler
to be used if Windoe.print() is called
(Printing Spec).handler
- the new PrintHandler
or null if you like to
ignore print requests (default is null)public FrameContentHandler getFrameContentHandler()
public void setFrameContentHandler(FrameContentHandler handler)
handler
- the new FrameContent handlerpublic void setOnbeforeunloadHandler(OnbeforeunloadHandler onbeforeunloadHandler)
WebClient
.onbeforeunloadHandler
- the new onbeforeunloadHandler or null if none is specifiedpublic OnbeforeunloadHandler getOnbeforeunloadHandler()
WebClient
.public Cache getCache()
public void setCache(Cache cache)
cache
- the new cache (must not be null
)public void close()
close
in interface AutoCloseable
public void reset()
Experimental API: May be changed in next release and may not yet work perfectly!
This shuts down the whole client and restarts with a new empty window. Cookies and other states are preserved.
public int waitForBackgroundJavaScript(long timeoutMillis)
Experimental API: May be changed in next release and may not yet work perfectly!
This method blocks until all background JavaScript tasks have finished executing. Background
JavaScript tasks are JavaScript tasks scheduled for execution via window.setTimeout
,
window.setInterval
or asynchronous XMLHttpRequest
.
If a job is scheduled to begin executing after (now + timeoutMillis)
, this method will
wait for timeoutMillis
milliseconds and then return a value greater than 0
. This
method will never block longer than timeoutMillis
milliseconds.
Use this method instead of waitForBackgroundJavaScriptStartingBefore(long)
if you
don't know when your background JavaScript is supposed to start executing, but you're fairly sure
that you know how long it should take to finish executing.
timeoutMillis
- the maximum amount of time to wait (in milliseconds)0
if there are no jobs left to executepublic int waitForBackgroundJavaScriptStartingBefore(long delayMillis)
Experimental API: May be changed in next release and may not yet work perfectly!
This method blocks until all background JavaScript tasks scheduled to start executing before
(now + delayMillis)
have finished executing. Background JavaScript tasks are JavaScript
tasks scheduled for execution via window.setTimeout
, window.setInterval
or
asynchronous XMLHttpRequest
.
If there is no background JavaScript task currently executing, and there is no background JavaScript
task scheduled to start executing within the specified time, this method returns immediately -- even
if there are tasks scheduled to be executed after (now + delayMillis)
.
Note that the total time spent executing a background JavaScript task is never known ahead of time, so this method makes no guarantees as to how long it will block.
Use this method instead of waitForBackgroundJavaScript(long)
if you know roughly when
your background JavaScript is supposed to start executing, but you're not necessarily sure how long
it will take to execute.
delayMillis
- the delay which determines the background tasks to wait for (in milliseconds)0
if there are no jobs left to executepublic void download(WebWindow requestingWindow, String target, WebRequest request, boolean checkHash, boolean forceLoad, String forceAttachmentWithFilename, String description)
requestingWindow
- the window from which the request comestarget
- the name of the target windowrequest
- the request to performcheckHash
- if true check for hashChenageforceLoad
- if true always load the request even if there is already the same in the queueforceAttachmentWithFilename
- if not null
the AttachmentHandler isAttachment() method is not called,
the response has to be handled as attachment in any casedescription
- information about the origin of the request. Useful for debugging.public void loadDownloadedResponses() throws FailingHttpStatusCodeException, IOException
IOException
- in case of exceptionFailingHttpStatusCodeException
- in case of exceptionpublic WebClientOptions getOptions()
public StorageHolder getStorageHolder()
Experimental API: May be changed in next release!
public Set<Cookie> getCookies(URL url)
url
- the URL on which to filter the returned cookiespublic void addCookie(String cookieString, URL pageUrl, Object origin)
cookieString
- the string to parsepageUrl
- the url of the page that likes to set the cookieorigin
- the requesterpublic boolean isJavaScriptEnabled()
WebClientOptions.setJavaScriptEnabled(boolean)
setter.isJavaScriptEngineEnabled()
,
WebClientOptions.isJavaScriptEnabled()
public boolean isJavaScriptEngineEnabled()
WebClient(BrowserVersion, boolean, String, int)
constructor.public HtmlPage loadHtmlCodeIntoCurrentWindow(String htmlCode) throws IOException
htmlCode
- the html code as stringIOException
- in case of errorpublic XHtmlPage loadXHtmlCodeIntoCurrentWindow(String xhtmlCode) throws IOException
xhtmlCode
- the xhtml code as stringIOException
- in case of errorpublic WebClient.PooledCSS3Parser getCSS3Parser()
Copyright © 2002–2024 Gargoyle Software Inc.. All rights reserved.