|
||||||||||
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.SgmlPage
com.gargoylesoftware.htmlunit.html.HtmlPage
public class HtmlPage
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 HtmlElement.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 = webClient.
getPage
("http://mywebsite/some/page.html");
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.gargoylesoftware.htmlunit.html.DomNode |
---|
DomNode.ChildIterator, DomNode.DescendantElementsIterator<T extends DomNode> |
Field Summary |
---|
Fields inherited from class com.gargoylesoftware.htmlunit.html.DomNode |
---|
AS_TEXT_BLANK, AS_TEXT_BLOCK_SEPARATOR, AS_TEXT_NEW_LINE, AS_TEXT_TAB, PROPERTY_ELEMENT, READY_STATE_COMPLETE, READY_STATE_INTERACTIVE, READY_STATE_LOADED, READY_STATE_LOADING, READY_STATE_UNINITIALIZED |
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. |
|
protected void |
checkChildHierarchy(Node newChild)
Check for insertion errors for a new child node. |
|
void |
cleanUp()
Clean up this page. |
|
protected HtmlPage |
clone()
Creates a clone of this instance, and clears cached state to be not shared with the original. |
|
HtmlPage |
cloneNode(boolean deep)
Override cloneNode to add cloned elements to the clone, not to the original. |
|
Attr |
createAttributeNS(String namespaceURI,
String qualifiedName)
Not yet implemented. |
|
CDATASection |
createCDATASection(String data)
|
|
Comment |
createComment(String data)
|
|
DocumentFragment |
createDocumentFragment()
|
|
HtmlElement |
createElement(String tagName)
Creates an element, the type of which depends on the specified tag name. |
|
HtmlElement |
createElementNS(String namespaceURI,
String qualifiedName)
Create a new Element with the given namespace and qualified name. |
|
EntityReference |
createEntityReference(String id)
Not yet implemented. |
|
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)
Executes the specified JavaScript code within the page. |
|
ScriptResult |
executeJavaScriptFunctionIfPossible(net.sourceforge.htmlunit.corejs.javascript.Function function,
net.sourceforge.htmlunit.corejs.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,
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. |
|
HtmlAnchor |
getAnchorByText(String text)
Returns the first anchor with the specified text. |
|
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. |
|
HtmlElement |
getDocumentElement()
Returns the document element. |
|
String |
getDocumentURI()
Not yet implemented. |
|
DOMConfiguration |
getDomConfig()
Not yet implemented. |
|
HtmlElement |
getElementByAccessKey(char accessKey)
Returns the HTML element that is assigned to the specified access key. |
|
HtmlElement |
getElementById(String elementId)
|
|
|
getElementByName(String name)
Returns the HTML element with the specified name. |
|
List<HtmlElement> |
getElementsByAccessKey(char accessKey)
Returns all the HTML elements that are assigned to the specified access key. |
|
List<HtmlElement> |
getElementsByIdAndOrName(String idAndOrName)
Returns the HTML elements with the specified string for their name or ID. |
|
List<HtmlElement> |
getElementsByName(String name)
Returns the HTML elements with the specified name attribute. |
|
DomNodeList<HtmlElement> |
getElementsByTagName(String tagName)
|
|
DomNodeList<HtmlElement> |
getElementsByTagNameNS(String namespaceURI,
String localName)
Not yet implemented. |
|
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. |
|
|
getHtmlElementById(String id)
Returns the HTML element with the specified ID. |
|
|
getHtmlElementById(String id,
boolean caseSensitive)
Returns the HTML element with the specified ID. |
|
DOMImplementation |
getImplementation()
Not yet implemented. |
|
String |
getInputEncoding()
Not yet implemented. |
|
protected List<HtmlMeta> |
getMetaTags(String httpEquiv)
Gets the meta tag for a given http-equiv value. |
|
Map<String,String> |
getNamespaces()
Returns all namespaces defined in the root element of this page. |
|
Document |
getOwnerDocument()
|
|
HtmlPage |
getPage()
Returns the page that contains this node. |
|
String |
getPageEncoding()
Returns the page encoding. |
|
String |
getResolvedTarget(String elementTarget)
Given a target attribute value, resolve the target using a base target for the page. |
|
List<org.w3c.dom.ranges.Range> |
getSelectionRanges()
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK. |
|
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. |
|
boolean |
hasCaseSensitiveTagNames()
Returns true if this page has case-sensitive tag names, false otherwise. |
|
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. |
|
boolean |
isOnbeforeunloadAccepted()
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK. |
|
boolean |
isQuirksMode()
Returns whether the current page mode is in quirks mode or in standards mode. |
|
HtmlElement |
pressAccessKey(char accessKey)
Simulate pressing an access key. |
|
DomNode |
querySelector(String selectors)
Returns the first element within the document that matches the specified group of selectors. |
|
DomNodeList<DomNode> |
querySelectorAll(String selectors)
Retrieves all element nodes from descendants of the starting element node that match any selector within the supplied selector strings. |
|
Page |
refresh()
Refreshes the page by sending the same parameters as previously sent to get this page. |
|
void |
removeHtmlAttributeChangeListener(HtmlAttributeChangeListener listener)
Removes an HtmlAttributeChangeListener from the listener list. |
|
Node |
renameNode(Node newNode,
String namespaceURI,
String qualifiedName)
Not yet implemented. |
|
void |
save(File file)
Saves the current page, with all images, to the specified location. |
|
protected void |
setDocumentType(DomDocumentType type)
Sets the document type. |
|
void |
setDocumentURI(String documentURI)
Not yet implemented. |
|
boolean |
setFocusedElement(HtmlElement newElement)
Moves the focus to the specified element. |
|
boolean |
setFocusedElement(HtmlElement newElement,
boolean windowActivated)
Moves the focus to the specified element. |
|
void |
setSelectionRange(org.w3c.dom.ranges.Range selectionRange)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK. |
|
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. |
|
void |
writeInParsedStream(String string)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK. |
Methods inherited from class com.gargoylesoftware.htmlunit.SgmlPage |
---|
asXml, createAttribute, createDomDocumentFragment, getCanonicalXPath, getDoctype, getEnclosingWindow, getNodeName, getNodeType, getUrl, getWebClient, getWebResponse, normalizeDocument, setEnclosingWindow |
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, getNodeValue, getParentNode, getPrefix, getPreviousSibling, getTextContent, getUserData, hasAttributes, hasChildNodes, insertBefore, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, normalize, removeChild, replaceChild, setNodeValue, setPrefix, setTextContent, setUserData |
Constructor Detail |
---|
public HtmlPage(URL originatingUrl, WebResponse webResponse, WebWindow webWindow)
WebClient.getPage(String)
.
originatingUrl
- the URL that was used to load this pagewebResponse
- the web response that was used to create this pagewebWindow
- the window that this page is being loaded intoMethod Detail |
---|
public HtmlPage getPage()
getPage
in class SgmlPage
public boolean hasCaseSensitiveTagNames()
hasCaseSensitiveTagNames
in class SgmlPage
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()
cleanUp
in interface Page
cleanUp
in class SgmlPage
public HtmlElement getDocumentElement()
getDocumentElement
in interface Document
getDocumentElement
in class SgmlPage
public HtmlElement getBody()
public Document getOwnerDocument()
getOwnerDocument
in interface Node
getOwnerDocument
in class DomNode
public Node importNode(Node importedNode, boolean deep)
public DomNodeList<HtmlElement> getElementsByTagName(String tagName)
public DomNodeList<HtmlElement> getElementsByTagNameNS(String namespaceURI, String localName)
public HtmlElement getElementById(String elementId)
public String getInputEncoding()
public String getXmlEncoding()
public boolean getXmlStandalone()
public void setXmlStandalone(boolean xmlStandalone) throws DOMException
DOMException
public String getXmlVersion()
public void setXmlVersion(String xmlVersion) throws DOMException
DOMException
public boolean getStrictErrorChecking()
public void setStrictErrorChecking(boolean strictErrorChecking)
public String getDocumentURI()
public void setDocumentURI(String documentURI)
public Node adoptNode(Node source) throws DOMException
DOMException
public DOMConfiguration getDomConfig()
public Node renameNode(Node newNode, String namespaceURI, String qualifiedName) throws DOMException
DOMException
public String getPageEncoding()
getPageEncoding
in class SgmlPage
public HtmlElement createElement(String tagName)
createElement
in interface Document
createElement
in class SgmlPage
tagName
- the tag name, preferably in lowercase
public HtmlElement createElementNS(String namespaceURI, String qualifiedName)
createElementNS
in interface Document
createElementNS
in class SgmlPage
namespaceURI
- the URI that identifies an XML namespacequalifiedName
- the qualified name of the element type to instantiate
public Attr createAttributeNS(String namespaceURI, String qualifiedName)
public Comment createComment(String data)
public Text createTextNode(String data)
public CDATASection createCDATASection(String data)
public DocumentFragment createDocumentFragment()
public DOMImplementation getImplementation()
public EntityReference createEntityReference(String id)
public ProcessingInstruction createProcessingInstruction(String namespaceURI, String qualifiedName)
public HtmlAnchor getAnchorByName(String name) throws ElementNotFoundException
HtmlAnchor
with the specified name.
name
- the name to search by
HtmlAnchor
with the specified name
ElementNotFoundException
- if the anchor could not be foundpublic HtmlAnchor getAnchorByHref(String href) throws ElementNotFoundException
HtmlAnchor
with the specified href.
href
- the string to search by
ElementNotFoundException
- if the anchor could not be foundpublic List<HtmlAnchor> getAnchors()
HtmlAnchor
in this pagepublic HtmlAnchor getAnchorByText(String text) throws ElementNotFoundException
text
- the text to search for
ElementNotFoundException
- if no anchors are found with the specified textpublic HtmlForm getFormByName(String name) throws ElementNotFoundException
name
- the name to search for
ElementNotFoundException
- If no forms match the specified result.public List<HtmlForm> getForms()
public URL getFullyQualifiedUrl(String relativeUrl) throws MalformedURLException
relativeUrl
- the relative URL
MalformedURLException
- 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<String> getTabbableElementIds()
getTabbableElements()
public List<HtmlElement> 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 getElementByAccessKey(char accessKey)
Only the following HTML elements may have accesskeys defined: A, AREA, BUTTON, INPUT, LABEL, LEGEND, and TEXTAREA.
accessKey
- the key to look for
public List<HtmlElement> getElementsByAccessKey(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 for
public ScriptResult executeJavaScript(String sourceCode)
Executes the specified JavaScript code within the page. The usage would be similar to what can be achieved to execute JavaScript in the current page by entering "javascript:...some JS code..." in the URL field of a native browser.
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, 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 executesourceName
- the name for this chunk of code (will be displayed in error messages)startLine
- the line at which the script source starts
public ScriptResult executeJavaScriptFunctionIfPossible(net.sourceforge.htmlunit.corejs.javascript.Function function, net.sourceforge.htmlunit.corejs.javascript.Scriptable thisObject, Object[] args, DomNode htmlElementScope)
function
- the JavaScript Function to callthisObject
- the "this" object to be used during invocationargs
- the arguments to pass into the callhtmlElementScope
- 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 String getTitleText()
public void setTitleText(String message)
message
- the new textpublic void deregisterFramesIfNeeded()
public List<FrameWindow> getFrames()
FrameWindow
public FrameWindow getFrameByName(String name) throws ElementNotFoundException
name
- the name to search for
ElementNotFoundException
- 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 <E extends HtmlElement> E getHtmlElementById(String id) throws ElementNotFoundException
E
- the element typeid
- the ID value to search for
ElementNotFoundException
- if no element was found matching the specified IDpublic <E extends HtmlElement> E getHtmlElementById(String id, boolean caseSensitive) throws ElementNotFoundException
E
- the element typeid
- the ID value to search forcaseSensitive
- whether to consider case sensitivity or not
ElementNotFoundException
- if no element was found matching the specified IDpublic <E extends HtmlElement> E getElementByName(String name) throws ElementNotFoundException
E
- the element typename
- the name value to search for
ElementNotFoundException
- if no element was found matching the specified namepublic List<HtmlElement> getElementsByName(String name)
name
- the name value to search for
public List<HtmlElement> getElementsByIdAndOrName(String idAndOrName)
idAndOrName
- the value to search for
public String toString()
toString
in class Object
public boolean setFocusedElement(HtmlElement newElement)
newElement
- the element that will receive the focus, use null
to remove focus from any element
getFocusedElement()
,
tabToNextElement()
,
tabToPreviousElement()
,
pressAccessKey(char)
,
WebAssert.assertAllTabIndexAttributesSet(HtmlPage)
public boolean setFocusedElement(HtmlElement newElement, boolean windowActivated)
newElement
- the element that will receive the focus, use null
to remove focus from any elementwindowActivated
- - whether the enclosing window got focus resulting in specified element getting focus
getFocusedElement()
,
tabToNextElement()
,
tabToPreviousElement()
,
pressAccessKey(char)
,
WebAssert.assertAllTabIndexAttributesSet(HtmlPage)
public HtmlElement getFocusedElement()
setFocusedElement(HtmlElement)
protected List<HtmlMeta> getMetaTags(String httpEquiv)
httpEquiv
- the http-equiv value
HtmlMeta
protected HtmlPage clone()
clone
in class SgmlPage
public HtmlPage cloneNode(boolean deep)
cloneNode
in interface Node
cloneNode
in class DomNode
public void addHtmlAttributeChangeListener(HtmlAttributeChangeListener listener)
listener
- the attribute change listener to be addedremoveHtmlAttributeChangeListener(HtmlAttributeChangeListener)
public void removeHtmlAttributeChangeListener(HtmlAttributeChangeListener listener)
listener
- the attribute change listener to be removedaddHtmlAttributeChangeListener(HtmlAttributeChangeListener)
protected void checkChildHierarchy(Node newChild) throws DOMException
checkChildHierarchy
in class DomNode
newChild
- the new child node that is being inserted below this node
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.public boolean isOnbeforeunloadAccepted()
public boolean isBeingParsed()
public Page refresh() throws IOException
IOException
- if an IO problem occurspublic void writeInParsedStream(String string)
Parses the given string as would it belong to the content being parsed at the current parsing position
string
- the HTML code to write in placepublic List<org.w3c.dom.ranges.Range> getSelectionRanges()
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Returns the page's current selection ranges. Note that some browsers, like IE, only allow a single selection at a time.
public void setSelectionRange(org.w3c.dom.ranges.Range selectionRange)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Makes the specified selection range the *only* selection range on this page.
selectionRange
- the selection rangepublic Map<String,String> getNamespaces()
Returns all namespaces defined in the root element of this page.
The default namespace has a key of an empty string.
protected void setDocumentType(DomDocumentType type)
setDocumentType
in class SgmlPage
type
- the document typepublic void save(File file) throws IOException
file
- file to write this page into
IOException
- If an error occurspublic boolean isQuirksMode()
public DomNodeList<DomNode> querySelectorAll(String selectors)
selectors
- one or more CSS selectors separated by commas
public DomNode querySelector(String selectors)
selectors
- one or more CSS selectors separated by commas
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |