com.gargoylesoftware.htmlunit.html
Class HtmlPage

java.lang.Object
  extended by com.gargoylesoftware.htmlunit.html.DomNode
      extended by com.gargoylesoftware.htmlunit.SgmlPage
          extended by com.gargoylesoftware.htmlunit.html.HtmlPage
All Implemented Interfaces:
Page, Serializable, Cloneable, Document, Node

public final class HtmlPage
extends SgmlPage
implements Cloneable, Document

A representation of an HTML page returned from a server.

This class provides different methods to access the page's content like getForms(), getAnchors(), getElementById(String), ... as well as the very powerful inherited methods DomNode.getByXPath(String) and DomNode.getFirstByXPath(String) for fine grained user specific access to child nodes.

Child elements allowing user interaction provide methods for this purpose like ClickableElement.click(), HtmlElement.type(String), HtmlOption.setSelected(boolean), ...

HtmlPage instances should not be instantiated directly. They will be returned by WebClient.getPage(String) when the content type of the server's response is text/html (or one of its variations).

Example:

final HtmlPage page = (HtmlPage) webClient.getPage("http://mywebsite/some/page.html");

Version:
$Revision: 2910 $
Author:
Mike Bowler, Alex Nikiforoff, Noboru Sinohara, David K. Taylor, Andreas Hangler, Christian Sell, Chris Erskine, Marc Guillemot, Ahmed Ashour, Daniel Gredler, Dmitri Zoubkov
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class com.gargoylesoftware.htmlunit.html.DomNode
DomNode.ChildIterator, DomNode.DescendantElementsIterator
 
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
 
Fields inherited from interface org.w3c.dom.Node
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_PRECEDING, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
 
Constructor Summary
HtmlPage(URL originatingUrl, WebResponse webResponse, WebWindow webWindow)
          Creates an instance of HtmlPage.
 
Method Summary
 void addHtmlAttributeChangeListener(HtmlAttributeChangeListener listener)
          Adds an HtmlAttributeChangeListener to the listener list.
 Node adoptNode(Node source)
           Not yet implemented.
 String asXml()
          Returns a string representation of the XML document from this element and all it's children (recursively).
protected  void checkChildHierarchy(Node newChild)
          Check for insertion errors for a new child node.
 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)
           Override cloneNode to add cloned elements to the clone, not to the original.
 Attr createAttribute(String qualifiedName)
           Not yet implemented.
 Attr createAttributeNS(String namespaceURI, String qualifiedName)
           Not yet implemented.
 CDATASection createCDATASection(String data)
          
 Comment createComment(String data)
          
 DocumentFragment createDocumentFragment()
          
 Element createElement(String tagName)
          
 Element createElementNS(String namespaceURI, String qualifiedName)
          
 EntityReference createEntityReference(String id)
           Not yet implemented.
 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.
 ProcessingInstruction createProcessingInstruction(String namespaceURI, String qualifiedName)
           Not yet implemented.
 Text createTextNode(String data)
          
 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. As of 1.14, 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)
          Returns the HtmlAnchor with the specified href.
 HtmlAnchor getAnchorByName(String name)
          Returns the HtmlAnchor with the specified name.
 List<HtmlAnchor> getAnchors()
          Returns a list of all anchors contained in this page.
 HtmlElement getBody()
          Returns the body element (or frameset element), or null if it does not yet exist.
 DocumentType getDoctype()
           Not yet implemented.
 HtmlElement getDocumentElement()
          
 HtmlElement getDocumentHtmlElement()
          Deprecated. As of 2.1, please use getDocumentElement() instead.
 String getDocumentURI()
           Not yet implemented.
 DOMConfiguration getDomConfig()
           Not yet implemented.
 Element getElementById(String elementId)
          
 NodeList getElementsByTagName(String tagName)
          
 NodeList getElementsByTagNameNS(String namespaceURI, String localName)
           Not yet implemented.
 HtmlElement getElementWithFocus()
          Deprecated. As of 2.0, please use getFocusedElement() instead.
 HtmlAnchor getFirstAnchorByText(String text)
          Returns the first anchor that contains the specified text.
 HtmlElement getFocusedElement()
          Returns the element with the focus or null if no element has the focus.
 HtmlForm getFormByName(String name)
          Returns the first form that matches the specified name.
 List<HtmlForm> getForms()
          Returns a list of all the forms in this page.
 FrameWindow getFrameByName(String name)
          Returns the first frame contained in this page with the specified name.
 List<FrameWindow> getFrames()
          Returns a list containing all the frames (from frame and iframe tags) in this page.
 URL getFullyQualifiedUrl(String relativeUrl)
          Given a relative URL (ie /foo), returns 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<HtmlElement> getHtmlElementsByAccessKey(char accessKey)
          Returns all the HTML elements that are assigned to the specified access key.
 List<HtmlElement> getHtmlElementsByIdAndOrName(String idAndOrName)
          Returns the HTML elements with the specified string for their name or ID.
 List<HtmlElement> getHtmlElementsByName(String name)
          Returns the HTML elements with the specified name attribute.
 DOMImplementation getImplementation()
           Not yet implemented.
 String getInputEncoding()
           Not yet implemented.
protected  Log getJsLog()
          Returns the log object for this element.
protected  List<HtmlMeta> getMetaTags(String httpEquiv)
          Gets the meta tag for a given http-equiv value.
 Document getOwnerDocument()
          
 HtmlPage getPage()
          Returns the page that contains this node.
 String getPageEncoding()
          Returns 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.
 boolean getStrictErrorChecking()
           Not yet implemented.
 List<String> getTabbableElementIds()
          Returns a list of ids (strings) that correspond to the tabbable elements in this page.
 List<HtmlElement> getTabbableElements()
          Returns a list of all elements that are tabbable in the order that will be used for tabbing.
 String getTitleText()
          Returns the title of this page or an empty string if the title wasn't specified.
 String getXmlEncoding()
           Not yet implemented.
 boolean getXmlStandalone()
           Not yet implemented.
 String getXmlVersion()
           Not yet implemented.
 Node importNode(Node importedNode, boolean deep)
           Not yet implemented.
 void initialize()
          Initialize this page.
 boolean isBeingParsed()
          Returns true if an HTML parser is operating on this page, adding content to it.
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)
          Deprecated. As of 2.0, please use setFocusedElement(HtmlElement) instead.
 void normalizeDocument()
           Not yet implemented.
 HtmlElement pressAccessKey(char accessKey)
          Simulate pressing an access key.
 void removeHtmlAttributeChangeListener(HtmlAttributeChangeListener listener)
          Removes an HtmlAttributeChangeListener from the listener list.
 Node renameNode(Node newNode, String namespaceURI, String qualifiedName)
           Not yet implemented.
 void setDocumentURI(String documentURI)
           Not yet implemented.
 boolean setFocusedElement(HtmlElement newElement)
          Moves the focus to the specified element.
 void setStrictErrorChecking(boolean strictErrorChecking)
           Not yet implemented.
 void setTitleText(String message)
          Sets the text for the title of this page.
 void setXmlStandalone(boolean xmlStandalone)
           Not yet implemented.
 void setXmlVersion(String xmlVersion)
           Not yet implemented.
 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.
 
Methods inherited from class com.gargoylesoftware.htmlunit.SgmlPage
createDomDocumentFragment, getEnclosingWindow, getNodeName, getNodeType, getWebClient, getWebResponse, setEnclosingWindow
 
Methods inherited from class com.gargoylesoftware.htmlunit.html.DomNode
addDomChangeListener, appendChild, appendDomChild, asText, cloneDomNode, compareDocumentPosition, fireNodeAdded, fireNodeDeleted, getAllHtmlChildElements, getAttributes, getBaseURI, getByXPath, getCanonicalXPath, getChildIterator, getChildNodes, getChildren, getChildrenAsText, getEndColumnNumber, getEndLineNumber, getFeature, getFirstByXPath, getFirstChild, getFirstDomChild, getLastChild, getLastDomChild, getLocalName, getLog, getNamespaceURI, getNextDomSibling, getNextSibling, getNodeValue, getParentDomNode, getParentNode, getPrefix, getPreviousDomSibling, getPreviousSibling, getReadyState, getScriptObject, getStartColumnNumber, getStartLineNumber, getTextContent, getUserData, hasAttributes, hasChildNodes, insertBefore, insertBefore, isAncestorOf, isDefaultNamespace, isEqualNode, isRenderedVisible, isSameNode, isSupported, isTrimmedText, lookupNamespaceURI, lookupPrefix, normalize, notifyIncorrectness, onAddedToPage, onAllChildrenAddedToPage, printChildrenAsXml, printXml, reduceWhitespace, remove, removeAllChildren, removeChild, removeDomChangeListener, replace, replaceChild, setNextSibling, setNodeValue, setParentNode, setPrefix, setPreviousSibling, setReadyState, setScriptObject, setTextContent, setUserData
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.w3c.dom.Node
appendChild, compareDocumentPosition, getAttributes, getBaseURI, getChildNodes, getFeature, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeName, getNodeType, getNodeValue, getParentNode, getPrefix, getPreviousSibling, getTextContent, getUserData, hasAttributes, hasChildNodes, insertBefore, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, normalize, removeChild, replaceChild, setNodeValue, setPrefix, setTextContent, setUserData
 

Constructor Detail

HtmlPage

public HtmlPage(URL originatingUrl,
                WebResponse webResponse,
                WebWindow webWindow)
Creates an instance of HtmlPage. An HtmlPage instance is normally retrieved with WebClient.getPage(String).

Parameters:
originatingUrl - the URL that was used to load this page
webResponse - the web response that was used to create this page
webWindow - the window that this page is being loaded into
Method Detail

getPage

public HtmlPage getPage()
Description copied from class: SgmlPage
Returns the page that contains this node.

Overrides:
getPage in class SgmlPage
Returns:
this page

initialize

public void initialize()
                throws IOException,
                       FailingHttpStatusCodeException
Initialize this page.

Specified by:
initialize in interface Page
Overrides:
initialize in class SgmlPage
Throws:
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.

cleanUp

public void cleanUp()
             throws IOException
Clean up this page.

Specified by:
cleanUp in interface Page
Overrides:
cleanUp in class SgmlPage
Throws:
IOException - if an IO problem occurs

getDocumentElement

public HtmlElement getDocumentElement()

Specified by:
getDocumentElement in interface Document

getDocumentHtmlElement

@Deprecated
public HtmlElement getDocumentHtmlElement()
Deprecated. As of 2.1, please use getDocumentElement() instead.

Gets the root HtmlElement of this document.

Returns:
the root element

getBody

public HtmlElement getBody()
Returns the body element (or frameset element), or null if it does not yet exist.

Returns:
the body element (or frameset element), or null if it does not yet exist

getOwnerDocument

public Document getOwnerDocument()

Specified by:
getOwnerDocument in interface Node
Overrides:
getOwnerDocument in class DomNode

importNode

public Node importNode(Node importedNode,
                       boolean deep)
Not yet implemented.

Specified by:
importNode in interface Document

getElementsByTagName

public NodeList getElementsByTagName(String tagName)

Specified by:
getElementsByTagName in interface Document

getElementsByTagNameNS

public NodeList getElementsByTagNameNS(String namespaceURI,
                                       String localName)
Not yet implemented.

Specified by:
getElementsByTagNameNS in interface Document

getElementById

public Element getElementById(String elementId)

Specified by:
getElementById in interface Document

getInputEncoding

public String getInputEncoding()
Not yet implemented.

Specified by:
getInputEncoding in interface Document

getXmlEncoding

public String getXmlEncoding()
Not yet implemented.

Specified by:
getXmlEncoding in interface Document

getXmlStandalone

public boolean getXmlStandalone()
Not yet implemented.

Specified by:
getXmlStandalone in interface Document

setXmlStandalone

public void setXmlStandalone(boolean xmlStandalone)
                      throws DOMException
Not yet implemented.

Specified by:
setXmlStandalone in interface Document
Throws:
DOMException

getXmlVersion

public String getXmlVersion()
Not yet implemented.

Specified by:
getXmlVersion in interface Document

setXmlVersion

public void setXmlVersion(String xmlVersion)
                   throws DOMException
Not yet implemented.

Specified by:
setXmlVersion in interface Document
Throws:
DOMException

getStrictErrorChecking

public boolean getStrictErrorChecking()
Not yet implemented.

Specified by:
getStrictErrorChecking in interface Document

setStrictErrorChecking

public void setStrictErrorChecking(boolean strictErrorChecking)
Not yet implemented.

Specified by:
setStrictErrorChecking in interface Document

getDocumentURI

public String getDocumentURI()
Not yet implemented.

Specified by:
getDocumentURI in interface Document

setDocumentURI

public void setDocumentURI(String documentURI)
Not yet implemented.

Specified by:
setDocumentURI in interface Document

adoptNode

public Node adoptNode(Node source)
               throws DOMException
Not yet implemented.

Specified by:
adoptNode in interface Document
Throws:
DOMException

getDomConfig

public DOMConfiguration getDomConfig()
Not yet implemented.

Specified by:
getDomConfig in interface Document

normalizeDocument

public void normalizeDocument()
Not yet implemented.

Specified by:
normalizeDocument in interface Document

renameNode

public Node renameNode(Node newNode,
                       String namespaceURI,
                       String qualifiedName)
                throws DOMException
Not yet implemented.

Specified by:
renameNode in interface Document
Throws:
DOMException

getPageEncoding

public String getPageEncoding()
Returns the charset used in the page. The sources of this information are from 1).meta element which http-equiv attribute value is 'content-type', or if not from the response header.

Returns:
the value of charset

createElement

public Element createElement(String tagName)

Specified by:
createElement in interface Document

createHtmlElement

public HtmlElement createHtmlElement(String tagName)
Create a new HTML element with the given tag name.

Parameters:
tagName - the tag name, preferably in lowercase
Returns:
the new HTML element

createElementNS

public Element createElementNS(String namespaceURI,
                               String qualifiedName)

Specified by:
createElementNS in interface Document

createHtmlElementNS

public HtmlElement createHtmlElementNS(String namespaceURI,
                                       String qualifiedName)
Create a new HtmlElement with the given namespace and qualified name.

Parameters:
namespaceURI - the URI that identifies an XML namespace
qualifiedName - the qualified name of the element type to instantiate
Returns:
the new HTML element

createAttributeNS

public Attr createAttributeNS(String namespaceURI,
                              String qualifiedName)
Not yet implemented.

Specified by:
createAttributeNS in interface Document

createAttribute

public Attr createAttribute(String qualifiedName)
Not yet implemented.

Specified by:
createAttribute in interface Document

createComment

public Comment createComment(String data)

Specified by:
createComment in interface Document

createTextNode

public Text createTextNode(String data)

Specified by:
createTextNode in interface Document

createCDATASection

public CDATASection createCDATASection(String data)

Specified by:
createCDATASection in interface Document

createDocumentFragment

public DocumentFragment createDocumentFragment()

Specified by:
createDocumentFragment in interface Document

getImplementation

public DOMImplementation getImplementation()
Not yet implemented.

Specified by:
getImplementation in interface Document

getDoctype

public DocumentType getDoctype()
Not yet implemented.

Specified by:
getDoctype in interface Document

createEntityReference

public EntityReference createEntityReference(String id)
Not yet implemented.

Specified by:
createEntityReference in interface Document

createProcessingInstruction

public ProcessingInstruction createProcessingInstruction(String namespaceURI,
                                                         String qualifiedName)
Not yet implemented.

Specified by:
createProcessingInstruction in interface Document

getAnchorByName

public HtmlAnchor getAnchorByName(String name)
                           throws ElementNotFoundException
Returns the HtmlAnchor with the specified name.

Parameters:
name - the name to search by
Returns:
the HtmlAnchor with the specified name
Throws:
ElementNotFoundException - if the anchor could not be found

getAnchorByHref

public HtmlAnchor getAnchorByHref(String href)
                           throws ElementNotFoundException
Returns the HtmlAnchor with the specified href.

Parameters:
href - the string to search by
Returns:
the HtmlAnchor
Throws:
ElementNotFoundException - if the anchor could not be found

getAnchors

public List<HtmlAnchor> getAnchors()
Returns a list of all anchors contained in this page.

Returns:
the list of HtmlAnchor in this page

getFirstAnchorByText

public HtmlAnchor getFirstAnchorByText(String text)
                                throws ElementNotFoundException
Returns the first anchor that contains the specified text.

Parameters:
text - the text to search for
Returns:
the first anchor that was found
Throws:
ElementNotFoundException - if no anchors are found with the specified text

getFormByName

public HtmlForm getFormByName(String name)
                       throws ElementNotFoundException
Returns the first form that matches the specified name.

Parameters:
name - the name to search for
Returns:
the first form
Throws:
ElementNotFoundException - If no forms match the specified result.

getForms

public List<HtmlForm> getForms()
Returns a list of all the forms in this page.

Returns:
all the forms in this page

getFullyQualifiedUrl

public URL getFullyQualifiedUrl(String relativeUrl)
                         throws MalformedURLException
Given a relative URL (ie /foo), returns a fully-qualified URL based on the URL that was used to load this page.

Parameters:
relativeUrl - the relative URL
Returns:
the fully-qualified URL for the specified relative URL
Throws:
MalformedURLException - If an error occurred when creating a URL object

getResolvedTarget

public String getResolvedTarget(String elementTarget)
Given a target attribute value, resolve the target using a base target for the page.

Parameters:
elementTarget - the target specified as an attribute of the element
Returns:
the resolved target to use for the element

getTabbableElementIds

public List<String> getTabbableElementIds()
Returns a list of ids (strings) that correspond to the tabbable elements in this page. Return them in the same order specified in getTabbableElements()

Returns:
the list of id's

getTabbableElements

public List<HtmlElement> getTabbableElements()
Returns a list of all elements that are tabbable in the order that will be used for tabbing.

The rules for determining tab order are as follows:

  1. Those elements that support the tabindex attribute and assign a positive value to it are navigated first. Navigation proceeds from the element with the lowest tabindex value to the element with the highest value. Values need not be sequential nor must they begin with any particular value. Elements that have identical tabindex values should be navigated in the order they appear in the character stream.
  2. Those elements that do not support the tabindex attribute or support it and assign it a value of "0" are navigated next. These elements are navigated in the order they appear in the character stream.
  3. Elements that are disabled do not participate in the tabbing order.
Additionally, the value of tabindex must be within 0 and 32767. Any values outside this range will be ignored.

The following elements support the tabindex attribute: A, AREA, BUTTON, INPUT, OBJECT, SELECT, and TEXTAREA.

Returns:
all the tabbable elements in proper tab order

getHtmlElementByAccessKey

public HtmlElement getHtmlElementByAccessKey(char accessKey)
Returns the HTML element that is assigned to the specified access key. An access key (aka mnemonic key) is used for keyboard navigation of the page.

Only the following HTML elements may have accesskeys defined: A, AREA, BUTTON, INPUT, LABEL, LEGEND, and TEXTAREA.

Parameters:
accessKey - the key to look for
Returns:
the HTML element that is assigned to the specified key or null if no elements can be found that match the specified key.

getHtmlElementsByAccessKey

public List<HtmlElement> getHtmlElementsByAccessKey(char accessKey)
Returns all the HTML elements that are assigned to the specified access key. An access key (aka mnemonic key) is used for keyboard navigation of the page.

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.

Parameters:
accessKey - the key to look for
Returns:
the elements that are assigned to the specified accesskey

executeJavaScript

public ScriptResult executeJavaScript(String sourceCode)
Execute the specified JavaScript within the page. The usage would be similar to what can be achieved to execute JavaScript in the current page by entering a "javascript:...some js code..." in the URL field of a "normal" browser.

Note: the provided code won't be executed if JavaScript has been disabled on the WebClient (see WebClient.isJavaScriptEnabled().

Parameters:
sourceCode - the JavaScript code to execute
Returns:
a ScriptResult which will contain both the current page (which may be different than the previous page) and a JavaScript result object

executeJavaScriptIfPossible

@Deprecated
public ScriptResult executeJavaScriptIfPossible(String sourceCode,
                                                           String sourceName,
                                                           HtmlElement htmlElement)
Deprecated. As of 1.14, use executeJavaScript(String) instead

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..

Parameters:
sourceCode - the JavaScript code to execute
sourceName - the name for this chunk of code (will be displayed in error messages)
htmlElement - the HTML element for which this script is being executed; will be the context during the JavaScript execution; if null, the context will default to the window
Returns:
a ScriptResult which will contain both the current page (which may be different than the previous page and a JavaScript result object

executeJavaScriptIfPossible

public ScriptResult executeJavaScriptIfPossible(String sourceCode,
                                                String sourceName,
                                                int startLine)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.

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..

Parameters:
sourceCode - the JavaScript code to execute
sourceName - the name for this chunk of code (will be displayed in error messages)
startLine - the line at which the script source starts
Returns:
a ScriptResult which will contain both the current page (which may be different than the previous page and a JavaScript result object.

executeJavaScriptFunctionIfPossible

public 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.

Parameters:
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.
Returns:
a ScriptResult which will contain both the current page (which may be different than the previous page and a JavaScript result object.

getJsLog

protected Log getJsLog()
Returns the log object for this element.

Returns:
the log object for this element

isJavaScript

public 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. According to W3C recommendation are content types case insensitive.

Parameters:
typeAttribute - the type attribute specified in the script tag
languageAttribute - the language attribute specified in the script tag
Returns:
true if the script is JavaScript

getTitleText

public String getTitleText()
Returns the title of this page or an empty string if the title wasn't specified.

Returns:
the title of this page or an empty string if the title wasn't specified

setTitleText

public void setTitleText(String message)
Sets the text for the title of this page. If there is not a title element on this page, then one has to be generated.

Parameters:
message - the new text

deregisterFramesIfNeeded

public void deregisterFramesIfNeeded()
Deregister frames that are no longer in use.


getFrames

public List<FrameWindow> getFrames()
Returns a list containing all the frames (from frame and iframe tags) in this page.

Returns:
a list of FrameWindow

getFrameByName

public FrameWindow getFrameByName(String name)
                           throws ElementNotFoundException
Returns the first frame contained in this page with the specified name.

Parameters:
name - the name to search for
Returns:
the first frame found
Throws:
ElementNotFoundException - If no frame exist in this page with the specified name.

pressAccessKey

public HtmlElement pressAccessKey(char accessKey)
                           throws IOException
Simulate pressing an access key. This may change the focus, may click buttons and may invoke JavaScript.

Parameters:
accessKey - the key that will be pressed
Returns:
the element that has the focus after pressing this access key or null if no element has the focus.
Throws:
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)

tabToNextElement

public HtmlElement tabToNextElement()
Move the focus to the next element in the tab order. To determine the specified tab order, refer to getTabbableElements()

Returns:
the element that has focus after calling this method

tabToPreviousElement

public HtmlElement tabToPreviousElement()
Move the focus to the previous element in the tab order. To determine the specified tab order, refer to getTabbableElements()

Returns:
the element that has focus after calling this method

getHtmlElementById

public HtmlElement getHtmlElementById(String id)
                               throws ElementNotFoundException
Returns the HTML element with the specified ID. If more than one element has this ID (not allowed by the HTML spec), then this method returns the first one.

Parameters:
id - the ID value to search by
Returns:
the HTML element with the specified ID
Throws:
ElementNotFoundException - if no element was found that matches the id

getHtmlElementsByName

public List<HtmlElement> getHtmlElementsByName(String name)
Returns the HTML elements with the specified name attribute. If there are no elements with the specified name, this method returns an empty list. Please note that the lists returned by this method are immutable.

Parameters:
name - the name value to search by
Returns:
the HTML elements with the specified name attribute

getHtmlElementsByIdAndOrName

public List<HtmlElement> getHtmlElementsByIdAndOrName(String idAndOrName)
Returns the HTML elements with the specified string for their name or ID. If there are no elements with the specified name or ID, this method returns an empty list. Please note that lists returned by this method are immutable.

Parameters:
idAndOrName - the value to search for
Returns:
the HTML elements with the specified string for their name or ID

asXml

public String asXml()
Returns a string representation of the XML document from this element and all it's children (recursively). The charset used is the current page encoding.

Overrides:
asXml in class DomNode
Returns:
the XML string

toString

public String toString()
Gives a basic representation for debugging purposes.

Overrides:
toString in class Object
Returns:
a basic representation

moveFocusToElement

@Deprecated
public boolean moveFocusToElement(HtmlElement newElement)
Deprecated. As of 2.0, please use setFocusedElement(HtmlElement) instead.

Moves the focus to the specified component. This will trigger any relevant JavaScript event handlers.

Parameters:
newElement - the element that will receive the focus, use null to remove focus from any element
Returns:
true if the specified element now has the focus
See Also:
getElementWithFocus(), tabToNextElement(), tabToPreviousElement(), pressAccessKey(char), WebAssert.assertAllTabIndexAttributesSet(HtmlPage)

setFocusedElement

public boolean setFocusedElement(HtmlElement newElement)
Moves the focus to the specified element. This will trigger any relevant JavaScript event handlers.

Parameters:
newElement - the element that will receive the focus, use null to remove focus from any element
Returns:
true if the specified element now has the focus
See Also:
getFocusedElement(), tabToNextElement(), tabToPreviousElement(), pressAccessKey(char), WebAssert.assertAllTabIndexAttributesSet(HtmlPage)

getElementWithFocus

@Deprecated
public HtmlElement getElementWithFocus()
Deprecated. As of 2.0, please use getFocusedElement() instead.

Returns the element with the focus or null if no element has the focus.

Returns:
the element with focus or null
See Also:
moveFocusToElement(HtmlElement)

getFocusedElement

public HtmlElement getFocusedElement()
Returns the element with the focus or null if no element has the focus.

Returns:
the element with focus or null
See Also:
setFocusedElement(HtmlElement)

getMetaTags

protected List<HtmlMeta> getMetaTags(String httpEquiv)
Gets the meta tag for a given http-equiv value.

Parameters:
httpEquiv - the http-equiv value
Returns:
a list of HtmlMeta

clone

protected Object clone()
Creates a clone of this instance, and clears cached state to be not shared with the original.

Overrides:
clone in class Object
Returns:
a clone of this instance

cloneNode

public DomNode cloneNode(boolean deep)
Override cloneNode to add cloned elements to the clone, not to the original.

Specified by:
cloneNode in interface Node
Overrides:
cloneNode in class DomNode

addHtmlAttributeChangeListener

public void addHtmlAttributeChangeListener(HtmlAttributeChangeListener listener)
Adds an HtmlAttributeChangeListener to the listener list. The listener is registered for all attributes of all HtmlElements contained in this page.

Parameters:
listener - the attribute change listener to be added
See Also:
removeHtmlAttributeChangeListener(HtmlAttributeChangeListener)

removeHtmlAttributeChangeListener

public void removeHtmlAttributeChangeListener(HtmlAttributeChangeListener listener)
Removes an HtmlAttributeChangeListener from the listener list. This method should be used to remove HtmlAttributeChangeListener that were registered for all attributes of all HtmlElements contained in this page.

Parameters:
listener - the attribute change listener to be removed
See Also:
addHtmlAttributeChangeListener(HtmlAttributeChangeListener)

checkChildHierarchy

protected void checkChildHierarchy(Node newChild)
                            throws DOMException
Check for insertion errors for a new child node. This is overridden by derived classes to enforce which types of children are allowed.

Overrides:
checkChildHierarchy in class DomNode
Parameters:
newChild - the new child node that is being inserted below this node
Throws:
DOMException - HIERARCHY_REQUEST_ERR: Raised if this node is of a type that does not allow children of the type of the newChild node, or if the node to insert is one of this node's ancestors or this node itself, or if this node is of type Document and the DOM application attempts to insert a second DocumentType or Element node. WRONG_DOCUMENT_ERR: Raised if newChild was created from a different document than the one that created this node.

isOnbeforeunloadAccepted

public boolean isOnbeforeunloadAccepted()
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.

Returns:
true if the OnbeforeunloadHandler has accepted to change the page

isBeingParsed

public boolean isBeingParsed()
Returns true if an HTML parser is operating on this page, adding content to it.

Returns:
true if an HTML parser is operating on this page, adding content to it


Copyright © 2002-2008 Gargoyle Software Inc.. All Rights Reserved.