|
|||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.gargoylesoftware.htmlunit.html.DomNode
com.gargoylesoftware.htmlunit.html.HtmlPage
public final class HtmlPage
A representation of an HTML page returned from a server. This class is the DOM Document implementation.
Field Summary |
---|
Fields inherited from class com.gargoylesoftware.htmlunit.html.DomNode |
---|
PROPERTY_ELEMENT, READY_STATE_COMPLETE, READY_STATE_INTERACTIVE, READY_STATE_LOADED, READY_STATE_LOADING, READY_STATE_UNINITIALIZED |
Constructor Summary | |
---|---|
HtmlPage(java.net.URL originatingUrl,
WebResponse webResponse,
WebWindow webWindow)
Create an instance of HtmlPage |
Method Summary | |
---|---|
void |
addHtmlAttributeChangeListener(HtmlAttributeChangeListener listener)
Adds an HtmlAttributeChangeListener to the listener list. |
void |
assertAllAccessKeyAttributesUnique()
Many html components can have an "accesskey" attribute which defines a hot key for keyboard navigation. |
void |
assertAllIdAttributesUnique()
Each html element can have an id attribute and by definition, all ids must be unique within the document. |
void |
assertAllTabIndexAttributesSet()
Many html elements are "tabbable" and can have a "tabindex" attribute that determines the order in which the components are navigated when pressing the tab key. |
java.lang.String |
asXml()
Return a string representation of the xml document from this element and all it's children (recursively). |
void |
cleanUp()
Clean up this page. |
DomNode |
cloneNode(boolean deep)
Override cloneNode to add cloned elements to the clone, not to the original. |
DomDocumentFragment |
createDomDocumentFragment()
Creates an empty DomDocumentFragment object. |
HtmlElement |
createHtmlElement(java.lang.String tagName)
Create a new HTML element with the given tag name. |
HtmlElement |
createHtmlElementNS(java.lang.String namespaceURI,
java.lang.String qualifiedName)
Create a new HtmlElement with the given namespace and qualified name. |
void |
deregisterFramesIfNeeded()
Deregister frames that are no longer in use. |
ScriptResult |
executeJavaScriptFunctionIfPossible(org.mozilla.javascript.Function function,
org.mozilla.javascript.Scriptable thisObject,
java.lang.Object[] args,
DomNode htmlElementScope)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK. |
ScriptResult |
executeJavaScriptIfPossible(java.lang.String sourceCode,
java.lang.String sourceName,
HtmlElement htmlElement)
Execute the specified javascript if a javascript engine was successfully instantiated. |
HtmlAnchor |
getAnchorByHref(java.lang.String href)
Return the HtmlAnchor with the specified href |
HtmlAnchor |
getAnchorByName(java.lang.String name)
Return the HtmlAnchor with the specified name |
java.util.List |
getAnchors()
Return a list of all anchors contained in this page. |
HtmlElement |
getDocumentHtmlElement()
Get the root HtmlElement of this document. |
FocusableElement |
getElementWithFocus()
Return the element with the focus or null if no element has the focus. |
WebWindow |
getEnclosingWindow()
Return the window that this page is sitting inside. |
HtmlAnchor |
getFirstAnchorByText(java.lang.String text)
Return the first anchor that contains the specified text. |
HtmlForm |
getFormByName(java.lang.String name)
Return the first form that matches the specified name |
java.util.List |
getForms()
Return a list of all the forms in the page. |
FrameWindow |
getFrameByName(java.lang.String name)
Returns the first frame contained in this page with the specified name. |
java.util.List |
getFrames()
Return a list containing all the frames (from frame and iframe tags) in this page. |
java.net.URL |
getFullyQualifiedUrl(java.lang.String relativeUrl)
Given a relative url (ie /foo), return a fully qualified url based on the url that was used to load this page |
HtmlElement |
getHtmlElementByAccessKey(char accessKey)
Return the html element that is assigned to the specified access key. |
HtmlElement |
getHtmlElementById(java.lang.String id)
Returns the HTML element with the specified ID. |
java.util.List |
getHtmlElementsByAccessKey(char accessKey)
Return all the html elements that are assigned to the specified access key. |
java.util.List |
getHtmlElementsByName(java.lang.String name)
Returns the HTML elements with the specified name attribute. |
java.lang.String |
getNodeName()
Get the name for the current node. |
short |
getNodeType()
Get the type of the current node. |
HtmlPage |
getPage()
Return the HtmlPage that contains this node |
java.lang.String |
getPageEncoding()
Return the charset used in the page. |
java.lang.String |
getResolvedTarget(java.lang.String elementTarget)
Given a target attribute value, resolve the target using a base target for the page. |
java.util.List |
getTabbableElementIds()
Return a list of ids (strings) that correspond to the tabbable elements in this page. |
java.util.List |
getTabbableElements()
Return a list of all elements that are tabbable in the order that will be used for tabbing. |
java.lang.String |
getTitleText()
Return the title of this page or an empty string if the title wasn't specified. |
WebClient |
getWebClient()
Return the WebClient that originally loaded this page |
WebResponse |
getWebResponse()
Return the web response that was originally used to create this page. |
void |
initialize()
Initialize this page. |
static boolean |
isJavaScript(java.lang.String typeAttribute,
java.lang.String languageAttribute)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK. |
boolean |
moveFocusToElement(FocusableElement newElement)
Move the focus to the specified component. |
HtmlElement |
pressAccessKey(char accessKey)
Simulate pressing an access key. |
void |
removeHtmlAttributeChangeListener(HtmlAttributeChangeListener listener)
Removes an HtmlAttributeChangeListener from the listener list. |
void |
setEnclosingWindow(WebWindow window)
Set the window that contains this page. |
void |
setTitleText(java.lang.String message)
Set the text for the title of this page. |
HtmlElement |
tabToNextElement()
Move the focus to the next element in the tab order. |
HtmlElement |
tabToPreviousElement()
Move the focus to the previous element in the tab order. |
java.lang.String |
toString()
Gives a basic representation for debugging purposes |
Methods inherited from class com.gargoylesoftware.htmlunit.html.DomNode |
---|
addDomChangeListener, appendDomChild, asText, cloneDomNode, getAllHtmlChildElements, getByXPath, getChildIterator, getEndColumnNumber, getEndLineNumber, getEventHandler, getFirstDomChild, getLastDomChild, getNextDomSibling, getNodeValue, getParentDomNode, getPreviousDomSibling, getReadyState, getScriptObject, getStartColumnNumber, getStartLineNumber, insertBefore, remove, removeAllChildren, removeDomChangeListener, removeEventHandler, replace, setEventHandler, setEventHandler, setNodeValue, setReadyState, setScriptObject |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public HtmlPage(java.net.URL originatingUrl, WebResponse webResponse, WebWindow webWindow)
originatingUrl
- The url that was used to load this page.webResponse
- The web response that was used to create this pagewebWindow
- The window that this page is being loaded into.Method Detail |
---|
public void addHtmlAttributeChangeListener(HtmlAttributeChangeListener listener)
listener
- the attribute change listener to be added.removeHtmlAttributeChangeListener(HtmlAttributeChangeListener)
public void assertAllAccessKeyAttributesUnique()
WebClient.assertionFailed(String)
public void assertAllIdAttributesUnique()
Assert that all ids in this page are unique. If they aren't then throw
an exception as per WebClient.assertionFailed(String)
public void assertAllTabIndexAttributesSet()
Assert that all tabbable elements have a valid value set for "tabindex".
If they don't then throw an exception as per WebClient.assertionFailed(String)
public java.lang.String asXml()
asXml
in class DomNode
public void cleanUp() throws java.io.IOException
cleanUp
in interface Page
java.io.IOException
- If an IO problem occurs.public DomNode cloneNode(boolean deep)
cloneNode
in class DomNode
deep
- if true
, the clone will be propagated to the whole subtree
below this one. Otherwise, the new node will not have any children. The page reference
will always be the same as this node's.
public DomDocumentFragment createDomDocumentFragment()
DomDocumentFragment
object.
DomDocumentFragment
.public HtmlElement createHtmlElement(java.lang.String tagName)
tagName
- The tag name, preferably in lowercase
public HtmlElement createHtmlElementNS(java.lang.String namespaceURI, java.lang.String qualifiedName)
namespaceURI
- the URI that identifies an XML namespace.qualifiedName
- The qualified name of the element type to instantiate
public void deregisterFramesIfNeeded()
public ScriptResult executeJavaScriptFunctionIfPossible(org.mozilla.javascript.Function function, org.mozilla.javascript.Scriptable thisObject, java.lang.Object[] args, DomNode htmlElementScope)
function
- The javascript Function to call.thisObject
- The "this" object to be used during invocation.args
- The arguments to pass into the call.htmlElementScope
- The html element for which this script is being executed.
This element will be the context during the javascript execution. If null,
the context will default to the page.
public ScriptResult executeJavaScriptIfPossible(java.lang.String sourceCode, java.lang.String sourceName, HtmlElement htmlElement)
Execute the specified javascript if a javascript engine was successfully instantiated. If this javascript causes the current page to be reloaded (through location="" or form.submit()) then return the new page. Otherwise return the current page.
Please note: Although this method is public, it is not intended for general execution of javascript. Users of HtmlUnit should interact with the pages as a user would by clicking on buttons or links and having the javascript event handlers execute as needed..
sourceCode
- The javascript code to execute.sourceName
- The name for this chunk of code. This name will be displayed
in any error messages.htmlElement
- The html element for which this script is being executed.
This element will be the context during the javascript execution. If null,
the context will default to the window.
public HtmlAnchor getAnchorByHref(java.lang.String href) throws ElementNotFoundException
HtmlAnchor
with the specified href
href
- The string to search by
ElementNotFoundException
- If the anchor could not be found.public HtmlAnchor getAnchorByName(java.lang.String name) throws ElementNotFoundException
name
- The name to search by
ElementNotFoundException
- If the anchor could not be found.public java.util.List getAnchors()
HtmlAnchor
in this page.public HtmlElement getDocumentHtmlElement()
public FocusableElement getElementWithFocus()
moveFocusToElement(FocusableElement)
public WebWindow getEnclosingWindow()
getEnclosingWindow
in interface Page
public HtmlAnchor getFirstAnchorByText(java.lang.String text) throws ElementNotFoundException
text
- The text to search for
ElementNotFoundException
- If no anchors are found with the specified textpublic HtmlForm getFormByName(java.lang.String name) throws ElementNotFoundException
name
- The name to search for
ElementNotFoundException
- If no forms match the specified result.public java.util.List getForms()
public FrameWindow getFrameByName(java.lang.String name) throws ElementNotFoundException
name
- The name to search for
ElementNotFoundException
- If no frame exist in this page with the specified name.public java.util.List getFrames()
FrameWindow
public java.net.URL getFullyQualifiedUrl(java.lang.String relativeUrl) throws java.net.MalformedURLException
relativeUrl
- The relative url
java.net.MalformedURLException
- If an error occurred when creating a
URL objectpublic HtmlElement getHtmlElementByAccessKey(char accessKey)
Only the following html elements may have accesskey's defined: A, AREA, BUTTON, INPUT, LABEL, LEGEND, and TEXTAREA.
accessKey
- The key to look for
public HtmlElement getHtmlElementById(java.lang.String id) throws ElementNotFoundException
id
- the ID value to search by
ElementNotFoundException
- if no element was found that matches the idpublic java.util.List getHtmlElementsByAccessKey(char accessKey)
The html specification seems to indicate that one accesskey cannot be used for multiple elements however Internet Explorer does seem to support this. It's worth noting that Mozilla does not support multiple elements with one access key so you are making your html browser specific if you rely on this feature.
Only the following html elements may have accesskey's defined: A, AREA, BUTTON, INPUT, LABEL, LEGEND, and TEXTAREA.
accessKey
- The key to look for
public java.util.List getHtmlElementsByName(java.lang.String name)
name
- the name value to search by
public java.lang.String getNodeName()
getNodeName
in class DomNode
public short getNodeType()
getNodeType
in class DomNode
public HtmlPage getPage()
DomNode
getPage
in class DomNode
public java.lang.String getPageEncoding()
public java.lang.String getResolvedTarget(java.lang.String elementTarget)
elementTarget
- The target specified as an attribute of the element.
public java.util.List getTabbableElementIds()
getTabbableElements()
public java.util.List getTabbableElements()
The rules for determing tab order are as follows:
The following elements support the tabindex attribute: A, AREA, BUTTON, INPUT, OBJECT, SELECT, and TEXTAREA.
public java.lang.String getTitleText()
public WebClient getWebClient()
public WebResponse getWebResponse()
getWebResponse
in interface Page
public void initialize() throws java.io.IOException, FailingHttpStatusCodeException
initialize
in interface Page
java.io.IOException
- If an IO problem occurs.
FailingHttpStatusCodeException
- If the server returns a
failing status code AND the property
WebClient.setThrowExceptionOnFailingStatusCode(boolean)
is set to true.public static boolean isJavaScript(java.lang.String typeAttribute, java.lang.String languageAttribute)
typeAttribute
- The type attribute specified in the script tag.languageAttribute
- The language attribute specified in the script tag.
public boolean moveFocusToElement(FocusableElement newElement)
newElement
- The element that will receive the focus, use null
to remove focus from any element
getElementWithFocus()
,
tabToNextElement()
,
tabToPreviousElement()
,
pressAccessKey(char)
,
assertAllTabIndexAttributesSet()
public HtmlElement pressAccessKey(char accessKey) throws java.io.IOException
accessKey
- The key that will be pressed.
java.io.IOException
- If an io error occurs during the processing of this access key. This
would only happen if the access key triggered a button which in turn caused a page load.public void removeHtmlAttributeChangeListener(HtmlAttributeChangeListener listener)
listener
- the attribute change listener to be removed.addHtmlAttributeChangeListener(HtmlAttributeChangeListener)
public void setEnclosingWindow(WebWindow window)
window
- The new frame or null if this page is being removed from a frame.public void setTitleText(java.lang.String message)
message
- The new textpublic HtmlElement tabToNextElement()
getTabbableElements()
public HtmlElement tabToPreviousElement()
getTabbableElements()
public java.lang.String toString()
toString
in class java.lang.Object
|
|||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |