public final class HtmlPage extends SgmlPage implements Cloneable
DomNode.ChildIterator, DomNode.DescendantElementsIterator
ATTRIBUTE_NODE, COMMENT_NODE, DOCUMENT_NODE, ELEMENT_NODE, PROPERTY_ELEMENT, READY_STATE_COMPLETE, READY_STATE_INTERACTIVE, READY_STATE_LOADED, READY_STATE_LOADING, READY_STATE_UNINITIALIZED, TEXT_NODE
Constructor and Description |
---|
HtmlPage(URL originatingUrl,
WebResponse webResponse,
WebWindow webWindow)
Create an instance of HtmlPage
|
Modifier and Type | Method and Description |
---|---|
void |
addHtmlAttributeChangeListener(HtmlAttributeChangeListener listener)
Adds an HtmlAttributeChangeListener to the listener list.
|
void |
assertAllAccessKeyAttributesUnique()
Deprecated.
|
void |
assertAllIdAttributesUnique()
Deprecated.
|
void |
assertAllTabIndexAttributesSet()
Deprecated.
|
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.
|
protected Object |
clone()
Creates a clone of this instance, and clears cached state
to be not shared with the original.
|
DomNode |
cloneNode(boolean deep)
Deprecated.
|
HtmlElement |
createElement(String tagName)
Deprecated.
This method conflicts with the W3C DOM API since the return values are
different. Use createHtmlElement instead.
|
HtmlElement |
createElementNS(String namespaceURI,
String qualifiedName)
Deprecated.
This method conflicts with the W3C DOM API since the return values are
different. Use createHtmlElementNS instead.
|
HtmlElement |
createHtmlElement(String tagName)
Create a new HTML element with the given tag name.
|
HtmlElement |
createHtmlElementNS(String namespaceURI,
String qualifiedName)
Create a new HtmlElement with the given namespace and qualified name.
|
void |
deregisterFramesIfNeeded()
Deregister frames that are no longer in use.
|
ScriptResult |
executeJavaScript(String sourceCode)
Execute the specified javascript within the page.
|
ScriptResult |
executeJavaScriptFunctionIfPossible(org.mozilla.javascript.Function function,
org.mozilla.javascript.Scriptable thisObject,
Object[] args,
DomNode htmlElementScope)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Execute a Function in the given context. |
ScriptResult |
executeJavaScriptIfPossible(String sourceCode,
String sourceName,
HtmlElement htmlElement)
Deprecated.
use
executeJavaScript(String) instead |
ScriptResult |
executeJavaScriptIfPossible(String sourceCode,
String sourceName,
int startLine)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
|
HtmlAnchor |
getAnchorByHref(String href)
Return the
HtmlAnchor with the specified href |
HtmlAnchor |
getAnchorByName(String name)
Return the HtmlAnchor with the specified name
|
List |
getAnchors()
Return a list of all anchors contained in this page.
|
HtmlElement |
getDocumentElement()
Deprecated.
This method conflicts with the W3C DOM API since the return values are
different. Use getDocumentHtmlElement instead.
|
HtmlElement |
getDocumentHtmlElement()
Get the root HtmlElement of this document.
|
HtmlElement |
getElementWithFocus()
Return the element with the focus or null if no element has the focus.
|
HtmlAnchor |
getFirstAnchorByText(String text)
Return the first anchor that contains the specified text.
|
HtmlForm |
getFormByName(String name)
Return the first form that matches the specified name
|
List |
getForms()
Return a list of all the forms in the page.
|
FrameWindow |
getFrameByName(String name)
Returns the first frame contained in this page with the specified name.
|
List |
getFrames()
Return a list containing all the frames (from frame and iframe tags) in this page.
|
URL |
getFullyQualifiedUrl(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)
Returns the HTML element that is assigned to the specified access key.
|
HtmlElement |
getHtmlElementById(String id)
Returns the HTML element with the specified ID.
|
List |
getHtmlElementsByAccessKey(char accessKey)
Returns all the HTML elements that are assigned to the specified access key.
|
List |
getHtmlElementsByIdAndOrName(String idAndOrName)
Returns the HTML elements with the specified string for their name or ID.
|
List |
getHtmlElementsByName(String name)
Returns the HTML elements with the specified name attribute.
|
protected org.apache.commons.logging.Log |
getJsLog()
Return the log object for this element.
|
protected List |
getMetaTags(String httpEquiv)
Gets the meta tag for a given http-equiv value.
|
HtmlPage |
getPage()
Return the HtmlPage that contains this node
|
String |
getPageEncoding()
Return the charset used in the page.
|
String |
getResolvedTarget(String elementTarget)
Given a target attribute value, resolve the target using a base target for the page.
|
List |
getTabbableElementIds()
Return a list of ids (strings) that correspond to the tabbable elements
in this page.
|
List |
getTabbableElements()
Returns a list of all elements that are tabbable in the order that will
be used for tabbing.
|
String |
getTitleText()
Return the title of this page or an empty string if the title wasn't specified.
|
void |
initialize()
Initialize this page.
|
static boolean |
isJavaScript(String typeAttribute,
String languageAttribute)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Return true if a script with the specified type and language attributes is actually JavaScript. |
boolean |
isOnbeforeunloadAccepted()
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
|
boolean |
moveFocusToElement(HtmlElement 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 |
setTitleText(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.
|
String |
toString()
Gives a basic representation for debugging purposes
|
createDomDocumentFragment, getEnclosingWindow, getNativePage, getNodeName, getNodeType, getWebClient, getWebResponse, setEnclosingWindow
addDomChangeListener, addPropertyChangeListener, appendChild, appendDomChild, asText, cloneDomNode, fireNodeAdded, fireNodeDeleted, firePropertyChange, getAllHtmlChildElements, getByXPath, getChildIterator, getChildrenAsText, getEndColumnNumber, getEndLineNumber, getEventHandler, getFirstByXPath, getFirstChild, getFirstDomChild, getLastChild, getLastDomChild, getLocalName, getLog, getNamespaceURI, getNextDomSibling, getNextSibling, getNodeValue, getParentDomNode, getParentNode, getPrefix, getPreviousDomSibling, getPreviousSibling, getReadyState, getScriptObject, getStartColumnNumber, getStartLineNumber, hasAttributes, insertBefore, isAncestorOf, isRenderedVisible, isTrimmedText, notifyIncorrectness, onAddedToPage, onAllChildrenAddedToPage, printChildrenAsXml, printXml, reduceWhitespace, remove, removeAllChildren, removeDomChangeListener, removeEventHandler, removePropertyChangeListener, replace, setEventHandler, setEventHandler, setNextSibling, setNodeValue, setParentNode, setPrefix, setPreviousSibling, setReadyState, setScriptObject
public HtmlPage(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.public HtmlPage getPage()
DomNode
public void initialize() throws IOException, FailingHttpStatusCodeException
initialize
in interface Page
initialize
in class SgmlPage
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 void cleanUp() throws IOException
cleanUp
in interface Page
cleanUp
in class SgmlPage
IOException
- If an IO problem occurs.public HtmlElement getDocumentElement()
public HtmlElement getDocumentHtmlElement()
public String getPageEncoding()
public HtmlElement createElement(String tagName)
tagName
- The tag name, preferably in lowercasepublic HtmlElement createHtmlElement(String tagName)
tagName
- The tag name, preferably in lowercasepublic HtmlElement createElementNS(String namespaceURI, String qualifiedName)
namespaceURI
- the URI that identifies an XML namespace.qualifiedName
- The qualified name of the element type to instantiatepublic HtmlElement createHtmlElementNS(String namespaceURI, String qualifiedName)
namespaceURI
- the URI that identifies an XML namespace.qualifiedName
- The qualified name of the element type to instantiatepublic HtmlAnchor getAnchorByName(String name) throws ElementNotFoundException
name
- The name to search byElementNotFoundException
- If the anchor could not be found.public HtmlAnchor getAnchorByHref(String href) throws ElementNotFoundException
HtmlAnchor
with the specified hrefhref
- The string to search byElementNotFoundException
- If the anchor could not be found.public List getAnchors()
HtmlAnchor
in this page.public HtmlAnchor getFirstAnchorByText(String text) throws ElementNotFoundException
text
- The text to search forElementNotFoundException
- If no anchors are found with the specified textpublic HtmlForm getFormByName(String name) throws ElementNotFoundException
name
- The name to search forElementNotFoundException
- If no forms match the specified result.public List getForms()
public URL getFullyQualifiedUrl(String relativeUrl) throws MalformedURLException
relativeUrl
- The relative urlMalformedURLException
- If an error occurred when creating a URL objectpublic String getResolvedTarget(String elementTarget)
elementTarget
- The target specified as an attribute of the element.public List getTabbableElementIds()
getTabbableElements()
public List getTabbableElements()
The rules for determining tab order are as follows:
The following elements support the tabindex attribute: A, AREA, BUTTON, INPUT, OBJECT, SELECT, and TEXTAREA.
public HtmlElement getHtmlElementByAccessKey(char accessKey)
Only the following HTML elements may have accesskeys defined: A, AREA, BUTTON, INPUT, LABEL, LEGEND, and TEXTAREA.
accessKey
- The key to look forpublic 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 accesskeys defined: A, AREA, BUTTON, INPUT, LABEL, LEGEND, and TEXTAREA.
accessKey
- The key to look forpublic 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 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 ScriptResult executeJavaScript(String sourceCode)
Note: the provided code won't be executed if JavaScript has been disabled on the WebClient
(see WebClient.isJavaScriptEnabled()
.
sourceCode
- The javascript code to execute.public ScriptResult executeJavaScriptIfPossible(String sourceCode, String sourceName, HtmlElement htmlElement)
executeJavaScript(String)
insteadExecute 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 ScriptResult executeJavaScriptIfPossible(String sourceCode, String sourceName, int startLine)
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.startLine
- the line at which the script source startspublic ScriptResult executeJavaScriptFunctionIfPossible(org.mozilla.javascript.Function function, org.mozilla.javascript.Scriptable thisObject, 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.protected org.apache.commons.logging.Log getJsLog()
public static boolean isJavaScript(String typeAttribute, String languageAttribute)
typeAttribute
- The type attribute specified in the script tag.languageAttribute
- The language attribute specified in the script tag.public String getTitleText()
public void setTitleText(String message)
message
- The new textpublic void deregisterFramesIfNeeded()
public List getFrames()
FrameWindow
public FrameWindow getFrameByName(String name) throws ElementNotFoundException
name
- The name to search forElementNotFoundException
- If no frame exist in this page with the specified name.public HtmlElement pressAccessKey(char accessKey) throws IOException
accessKey
- The key that will be pressed.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 HtmlElement tabToNextElement()
getTabbableElements()
public HtmlElement tabToPreviousElement()
getTabbableElements()
public HtmlElement getHtmlElementById(String id) throws ElementNotFoundException
id
- the ID value to search byElementNotFoundException
- if no element was found that matches the idpublic List getHtmlElementsByName(String name)
name
- the name value to search bypublic List getHtmlElementsByIdAndOrName(String idAndOrName)
idAndOrName
- the value to search forpublic String asXml()
public String toString()
public boolean moveFocusToElement(HtmlElement newElement)
newElement
- The element that will receive the focus, use null
to remove focus from any elementgetElementWithFocus()
,
tabToNextElement()
,
tabToPreviousElement()
,
pressAccessKey(char)
,
assertAllTabIndexAttributesSet()
public HtmlElement getElementWithFocus()
moveFocusToElement(HtmlElement)
protected List getMetaTags(String httpEquiv)
httpEquiv
- the http-equiv valueHtmlMeta
protected Object clone()
public DomNode cloneNode(boolean deep)
public void addHtmlAttributeChangeListener(HtmlAttributeChangeListener listener)
listener
- the attribute change listener to be added.removeHtmlAttributeChangeListener(HtmlAttributeChangeListener)
public void removeHtmlAttributeChangeListener(HtmlAttributeChangeListener listener)
listener
- the attribute change listener to be removed.addHtmlAttributeChangeListener(HtmlAttributeChangeListener)
public boolean isOnbeforeunloadAccepted()
Copyright © 2002-2012 Gargoyle Software Inc.. All Rights Reserved.