|
|||||
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.DomNamespaceNode
com.gargoylesoftware.htmlunit.html.HtmlElement
public abstract class HtmlElement
An abstract wrapper for html elements
Nested Class Summary | |
---|---|
static class |
HtmlElement.MapEntryWrappingIterator
Converts an iteration of plain Map.Entry into an iteration of HtmlAttr . |
Field Summary | |
---|---|
static java.lang.String |
ATTRIBUTE_NOT_DEFINED
Constant meaning that the specified attribute was not defined. |
static java.lang.String |
ATTRIBUTE_VALUE_EMPTY
Constant meaning that the specified attribute was found but its value was empty. |
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 |
Method Summary | |
---|---|
void |
addHtmlAttributeChangeListener(HtmlAttributeChangeListener listener)
Adds an HtmlAttributeChangeListener to the listener list. |
HtmlElement |
appendChildIfNoneExists(java.lang.String tagName)
Appends a child element to this HTML element with the specified tag name if this HTML element does not already have a child with that tag name. |
DomNode |
cloneDomNode(boolean deep)
Overrides DomNode.cloneDomNode(boolean) so clone gets its own Map of attributes. |
ScriptResult |
fireEvent(Event event)
Fire the event on the element. |
ScriptResult |
fireEvent(java.lang.String eventType)
Shortcut for fireEvent(Event) . |
java.util.Iterator |
getAttributeEntriesIterator()
|
java.lang.String |
getAttributeValue(java.lang.String attributeName)
Return the value of the specified attribute or an empty string. |
java.util.Iterator |
getChildElementsIterator()
|
HtmlElement |
getEnclosingElement(java.lang.String tagName)
Return the element with the given name that enclosed this element or null if this element is no such element is found. |
HtmlForm |
getEnclosingForm()
Return the form that enclosed this element or null if this element is not within a form. |
HtmlForm |
getEnclosingFormOrDie()
Return the form that enclosed this element or throw an exception if this element is not within a form. |
org.mozilla.javascript.Function |
getEventHandler(java.lang.String eventName)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK. |
HtmlElement |
getHtmlElementById(java.lang.String id)
Return the html element with the specified id. |
java.util.List |
getHtmlElementsByAttribute(java.lang.String elementName,
java.lang.String attributeName,
java.lang.String attributeValue)
Search by the specified criteria and return all the HtmlElement that are found |
java.util.List |
getHtmlElementsByTagName(java.lang.String tagName)
Given a list of tag names, return the html elements that correspond to any matching element |
java.util.List |
getHtmlElementsByTagNames(java.util.List acceptableTagNames)
Given a list of tag names, return the html elements that correspond to any matching element |
java.lang.String |
getId()
|
java.lang.String |
getNodeName()
Get the name for the current node. |
short |
getNodeType()
Get the type of the current node. |
HtmlElement |
getOneHtmlElementByAttribute(java.lang.String elementName,
java.lang.String attributeName,
java.lang.String attributeValue)
Search by the specified criteria and return the first HtmlElement that is found |
java.lang.String |
getTagName()
Return the tag name of this element. |
boolean |
hasHtmlElementWithId(java.lang.String id)
Return true if there is a element with the specified id. |
boolean |
isAttributeDefined(java.lang.String attributeName)
Return true if the specified attribute has been defined. |
void |
keyDown(int keyCode)
Simulate pressing a key on this element |
void |
keyDown(int keyCode,
boolean shiftKey,
boolean ctrlKey,
boolean altKey)
Simulate pressing a key on this element |
Page |
mouseDown()
Simulate clicking the mouse in this element. |
Page |
mouseDown(boolean shiftKey,
boolean ctrlKey,
boolean altKey,
int button)
Simulate clicking the mouse in this element. |
Page |
mouseMove()
Simulate moving the mouse inside this element. |
Page |
mouseMove(boolean shiftKey,
boolean ctrlKey,
boolean altKey,
int button)
Simulate moving the mouse inside this element. |
Page |
mouseOut()
Simulate moving the mouse out of this element. |
Page |
mouseOut(boolean shiftKey,
boolean ctrlKey,
boolean altKey,
int button)
Simulate moving the mouse out of this element. |
Page |
mouseOver()
Simulate moving the mouse over this element. |
Page |
mouseOver(boolean shiftKey,
boolean ctrlKey,
boolean altKey,
int button)
Simulate moving the mouse over this element. |
Page |
mouseUp()
Simulate releasing the mouse click in this element. |
Page |
mouseUp(boolean shiftKey,
boolean ctrlKey,
boolean altKey,
int button)
Simulate releasing the mouse click in this element. |
void |
removeAttribute(java.lang.String attributeName)
Removes an attribute from this element. |
void |
removeChild(java.lang.String tagName,
int i)
Removes the ith child element with the specified tag name from all relationships, if possible. |
void |
removeEventHandler(java.lang.String eventName)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK. |
void |
removeHtmlAttributeChangeListener(HtmlAttributeChangeListener listener)
Removes an HtmlAttributeChangeListener from the listener list. |
Page |
rightClick()
Simulate right clicking the mouse in this element. |
Page |
rightClick(boolean shiftKey,
boolean ctrlKey,
boolean altKey)
Simulate right clicking the mouse in this element. |
void |
setAttributeValue(java.lang.String attributeName,
java.lang.String attributeValue)
Set the value of the specified attribute. |
void |
setEventHandler(java.lang.String eventName,
org.mozilla.javascript.Function eventHandler)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK. |
void |
setEventHandler(java.lang.String eventName,
java.lang.String jsSnippet)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK. |
void |
setId(java.lang.String newId)
Set the identifier this element. |
java.lang.String |
toString()
Return a string representation of this object |
Methods inherited from class com.gargoylesoftware.htmlunit.html.DomNamespaceNode |
---|
getLocalName, getNamespaceURI, getPrefix, getQualifiedName, setPrefix |
Methods inherited from class com.gargoylesoftware.htmlunit.html.DomNode |
---|
addDomChangeListener, appendDomChild, asText, asXml, getAllHtmlChildElements, getByXPath, getChildIterator, getEndColumnNumber, getEndLineNumber, getFirstDomChild, getLastDomChild, getNextDomSibling, getNodeValue, getPage, getParentDomNode, getPreviousDomSibling, getReadyState, getScriptObject, getStartColumnNumber, getStartLineNumber, insertBefore, remove, removeAllChildren, removeDomChangeListener, replace, setNodeValue, setReadyState, setScriptObject |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String ATTRIBUTE_NOT_DEFINED
public static final java.lang.String ATTRIBUTE_VALUE_EMPTY
Method Detail |
---|
public void addHtmlAttributeChangeListener(HtmlAttributeChangeListener listener)
listener
- the attribute change listener to be added.removeHtmlAttributeChangeListener(HtmlAttributeChangeListener)
public final HtmlElement appendChildIfNoneExists(java.lang.String tagName)
tagName
- the tag name of the child to append
public DomNode cloneDomNode(boolean deep)
DomNode.cloneDomNode(boolean)
so clone gets its own Map of attributes.
Make a clone of this node
cloneDomNode
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 ScriptResult fireEvent(Event event)
event
- the event to fire.
null
if nothing is executed.public ScriptResult fireEvent(java.lang.String eventType)
fireEvent(Event)
.
eventType
- the event type (like "load", "click")
null
if nothing is executed.public java.util.Iterator getAttributeEntriesIterator()
HtmlAttr
objects representing the
attributes of this element. Each entry holds a string key and a string value.
The elements are ordered as found in the html source code.public final java.lang.String getAttributeValue(java.lang.String attributeName)
ATTRIBUTE_NOT_DEFINED
if the attribute wasn't specified or ATTRIBUTE_VALUE_EMPTY
if the
attribute was specified but it was empty.
attributeName
- the name of the attribute
ATTRIBUTE_NOT_DEFINED
or ATTRIBUTE_VALUE_EMPTY
public final java.util.Iterator getChildElementsIterator()
public HtmlElement getEnclosingElement(java.lang.String tagName)
tagName
- the name of the tag searched (case insensitive)
public HtmlForm getEnclosingForm()
public HtmlForm getEnclosingFormOrDie() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- If the element is not within a form.public final org.mozilla.javascript.Function getEventHandler(java.lang.String eventName)
getEventHandler
in class DomNode
eventName
- Name of event such as "onclick" or "onblur", etc.
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 final java.util.List getHtmlElementsByAttribute(java.lang.String elementName, java.lang.String attributeName, java.lang.String attributeValue)
elementName
- The name of the elementattributeName
- The name of the attributeattributeValue
- The value of the attribute
public final java.util.List getHtmlElementsByTagName(java.lang.String tagName)
tagName
- the tag name to match
public final java.util.List getHtmlElementsByTagNames(java.util.List acceptableTagNames)
acceptableTagNames
- The list of tag names to search by.
public final java.lang.String getId()
public java.lang.String getNodeName()
DomNode
getNodeName
in class DomNode
getTagName()
,public short getNodeType()
DomNode
getNodeType
in class DomNode
public final HtmlElement getOneHtmlElementByAttribute(java.lang.String elementName, java.lang.String attributeName, java.lang.String attributeValue) throws ElementNotFoundException
elementName
- The name of the elementattributeName
- The name of the attributeattributeValue
- The value of the attribute
ElementNotFoundException
- If a particular xml element could
not be found in the dom modelpublic java.lang.String getTagName()
public boolean hasHtmlElementWithId(java.lang.String id)
Implementation note: This method calls getHtmlElementById() internally so writing code like the following would be extremely inefficient.
if (hasHtmlElementWithId(id)) { HtmlElement element = getHtmlElementWithId(id) ... }
id
- The id to search by
public boolean isAttributeDefined(java.lang.String attributeName)
attributeName
- The attribute to check
public void keyDown(int keyCode)
keyCode
- the key you wish to presspublic void keyDown(int keyCode, boolean shiftKey, boolean ctrlKey, boolean altKey)
keyCode
- the key you wish to pressshiftKey
- true if SHIFT is pressedctrlKey
- true if CTRL is pressedaltKey
- true if ALT is pressedpublic Page mouseDown()
public Page mouseDown(boolean shiftKey, boolean ctrlKey, boolean altKey, int button)
shiftKey
- true if SHIFT is pressedctrlKey
- true if CTRL is pressedaltKey
- true if ALT is pressedbutton
- the button code, must be MouseEvent.BUTTON_LEFT
, MouseEvent.BUTTON_MIDDLE
or MouseEvent.BUTTON_RIGHT
public Page mouseMove()
public Page mouseMove(boolean shiftKey, boolean ctrlKey, boolean altKey, int button)
shiftKey
- true if SHIFT is pressedctrlKey
- true if CTRL is pressedaltKey
- true if ALT is pressedbutton
- the button code, must be MouseEvent.BUTTON_LEFT
, MouseEvent.BUTTON_MIDDLE
or MouseEvent.BUTTON_RIGHT
public Page mouseOut()
public Page mouseOut(boolean shiftKey, boolean ctrlKey, boolean altKey, int button)
shiftKey
- true if SHIFT is pressedctrlKey
- true if CTRL is pressedaltKey
- true if ALT is pressedbutton
- the button code, must be MouseEvent.BUTTON_LEFT
, MouseEvent.BUTTON_MIDDLE
or MouseEvent.BUTTON_RIGHT
public Page mouseOver()
public Page mouseOver(boolean shiftKey, boolean ctrlKey, boolean altKey, int button)
shiftKey
- true if SHIFT is pressedctrlKey
- true if CTRL is pressedaltKey
- true if ALT is pressedbutton
- the button code, must be MouseEvent.BUTTON_LEFT
, MouseEvent.BUTTON_MIDDLE
or MouseEvent.BUTTON_RIGHT
public Page mouseUp()
public Page mouseUp(boolean shiftKey, boolean ctrlKey, boolean altKey, int button)
shiftKey
- true if SHIFT is pressedctrlKey
- true if CTRL is pressedaltKey
- true if ALT is pressedbutton
- the button code, must be MouseEvent.BUTTON_LEFT
, MouseEvent.BUTTON_MIDDLE
or MouseEvent.BUTTON_RIGHT
public final void removeAttribute(java.lang.String attributeName)
attributeName
- the attribute attributeNamepublic final void removeChild(java.lang.String tagName, int i)
tagName
- the tag name of the child to removei
- the index of the child to removepublic final void removeEventHandler(java.lang.String eventName)
removeEventHandler
in class DomNode
eventName
- Name of the event such as "onclick" or "onblur", etc.public void removeHtmlAttributeChangeListener(HtmlAttributeChangeListener listener)
listener
- the attribute change listener to be removed.addHtmlAttributeChangeListener(HtmlAttributeChangeListener)
public Page rightClick()
public Page rightClick(boolean shiftKey, boolean ctrlKey, boolean altKey)
This is equivalent to calling mouseDown(boolean, boolean, boolean, int)
,
then mouseUp(boolean, boolean, boolean, int)
shiftKey
- true if SHIFT is pressedctrlKey
- true if CTRL is pressedaltKey
- true if ALT is pressed
public final void setAttributeValue(java.lang.String attributeName, java.lang.String attributeValue)
attributeName
- the name of the attributeattributeValue
- The value of the attributepublic final void setEventHandler(java.lang.String eventName, org.mozilla.javascript.Function eventHandler)
setEventHandler
in class DomNode
eventName
- Name of event such as "onclick" or "onblur", etc.eventHandler
- A rhino javascript executable Functionpublic final void setEventHandler(java.lang.String eventName, java.lang.String jsSnippet)
setEventHandler
in class DomNode
eventName
- Name of event such as "onclick" or "onblur", etc.jsSnippet
- executable javascript codepublic final void setId(java.lang.String newId)
newId
- The new identifier of this element.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 |