public abstract class HtmlElement extends DomElement
| Modifier and Type | Class and Description |
|---|---|
static class |
HtmlElement.DisplayStyle
Enum for the different display styles.
|
DomElement.ChildElementsIteratorDomNode.ChildIterator, DomNode.DescendantElementsIterator<T extends DomNode>| Modifier and Type | Field and Description |
|---|---|
static Short |
TAB_INDEX_OUT_OF_BOUNDS
Constant indicating that a tab index value is out of bounds (less than 0 or greater
than 32767).
|
ATTRIBUTE_NOT_DEFINED, ATTRIBUTE_VALUE_EMPTYAS_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_UNINITIALIZEDATTRIBUTE_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| Modifier | Constructor and Description |
|---|---|
protected |
HtmlElement(String qualifiedName,
SgmlPage page,
Map<String,DomAttr> attributes)
Creates an instance.
|
| Modifier and Type | Method and Description |
|---|---|
protected boolean |
acceptChar(char c)
Indicates if the provided character can by "typed" in the element.
|
void |
addHtmlAttributeChangeListener(HtmlAttributeChangeListener listener)
Adds an HtmlAttributeChangeListener to the listener list.
|
HtmlElement |
appendChildIfNoneExists(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.
|
protected void |
checkChildHierarchy(Node childNode)
Check for insertion errors for a new child node.
|
protected void |
detach()
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Detach this node from all relationships with other nodes. |
protected void |
doType(char c,
boolean shiftKey,
boolean ctrlKey,
boolean altKey)
Performs the effective type action, called after the keyPress event and before the keyUp event.
|
protected void |
doType(int keyCode,
boolean shiftKey,
boolean ctrlKey,
boolean altKey)
Performs the effective type action, called after the keyPress event and before the keyUp event.
|
protected void |
fireHtmlAttributeAdded(HtmlAttributeChangeEvent event)
Support for reporting HTML attribute changes.
|
protected void |
fireHtmlAttributeRemoved(HtmlAttributeChangeEvent event)
Support for reporting HTML attribute changes.
|
protected void |
fireHtmlAttributeReplaced(HtmlAttributeChangeEvent event)
Support for reporting HTML attribute changes.
|
String |
getCanonicalXPath()
Returns the canonical XPath expression which identifies this node, for instance
"/html/body/table[3]/tbody/tr[5]/td[2]/span/a[3]".
|
HtmlElement.DisplayStyle |
getDefaultStyleDisplay()
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Returns the default display style. |
<E extends HtmlElement> |
getElementsByAttribute(String elementName,
String attributeName,
String attributeValue)
Returns all elements which are descendants of this element and match the specified search criteria.
|
HtmlElement |
getEnclosingElement(String tagName)
Returns the first element with the specified tag name that is an ancestor to this element, or
null if no such element is found. |
HtmlForm |
getEnclosingForm()
Returns the form which contains this element, or
null if this element is not inside
of a form. |
HtmlForm |
getEnclosingFormOrDie()
Returns the form which contains this element.
|
<E extends HtmlElement> |
getHtmlElementsByTagName(String tagName)
Deprecated.
as of 2.21, please use
DomElement.getElementsByTagName(String), which returns read-only list |
List<HtmlElement> |
getHtmlElementsByTagNames(List<String> tagNames)
Deprecated.
as of 2.21, please use
DomElement.getElementsByTagName(String) |
String |
getLangAttribute()
Returns the value of the attribute
lang. |
String |
getNodeName()
Returns this node's node name.
|
String |
getOnClickAttribute()
Returns the value of the attribute
onclick. |
String |
getOnDblClickAttribute()
Returns the value of the attribute
ondblclick. |
<E extends HtmlElement> |
getOneHtmlElementByAttribute(String elementName,
String attributeName,
String attributeValue)
Searches for an element based on the specified criteria, returning the first element which matches
said criteria.
|
String |
getOnKeyDownAttribute()
Returns the value of the attribute
onkeydown. |
String |
getOnKeyPressAttribute()
Returns the value of the attribute
onkeypress. |
String |
getOnKeyUpAttribute()
Returns the value of the attribute
onkeyup. |
String |
getOnMouseDownAttribute()
Returns the value of the attribute
onmousedown. |
String |
getOnMouseMoveAttribute()
Returns the value of the attribute
onmousemove. |
String |
getOnMouseOutAttribute()
Returns the value of the attribute
onmouseout. |
String |
getOnMouseOverAttribute()
Returns the value of the attribute
onmouseover. |
String |
getOnMouseUpAttribute()
Returns the value of the attribute
onmouseup. |
protected String |
getSrcAttributeNormalized()
Helper for src retrieval and normalization.
|
Short |
getTabIndex()
Returns this element's tab index, if it has one.
|
String |
getTextDirectionAttribute()
Returns the value of the attribute
dir. |
String |
getXmlLangAttribute()
Returns the value of the attribute
xml:lang. |
boolean |
handles(Event event)
Indicates if the provided event can be applied to this node.
|
boolean |
hasEventHandlers(String eventName)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Returns true if this element has any JavaScript functions that need to be executed when the
specified event occurs. |
protected boolean |
isAttributeCaseSensitive()
Indicates if the attribute names are case sensitive.
|
boolean |
isDisplayed()
Returns
true if this node is displayed and can be visible to the user
(ignoring screen size, scrolling limitations, color, font-size, or overlapping nodes). |
protected boolean |
isSubmittableByEnter()
Returns
true if clicking Enter (ASCII 10, or '\n') should submit the enclosed form (if any). |
void |
removeAttribute(String attributeName)
Removes an attribute specified by name from this element.
|
void |
removeChild(String tagName,
int i)
Removes the ith child element with the specified tag name
from all relationships, if possible.
|
void |
removeEventHandler(String eventName)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Removes the specified event handler. |
void |
removeHtmlAttributeChangeListener(HtmlAttributeChangeListener listener)
Removes an HtmlAttributeChangeListener from the listener list.
|
Attr |
setAttributeNode(Attr attribute)
Sets the specified attribute.
|
void |
setAttributeNS(String namespaceURI,
String qualifiedName,
String attributeValue)
Sets the value of the specified attribute.
|
void |
setEventHandler(String eventName,
net.sourceforge.htmlunit.corejs.javascript.Function eventHandler)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Registers a JavaScript function as an event handler. |
void |
setEventHandler(String eventName,
String jsSnippet)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.
Register a snippet of JavaScript code as an event handler. |
void |
setId(String newId)
Sets the identifier this element.
|
Page |
type(char c)
Simulates typing the specified character while this element has focus, returning the page contained
by this element's window after typing.
|
Page |
type(char c,
boolean shiftKey,
boolean ctrlKey,
boolean altKey)
Deprecated.
as of 2.18, please use
type(Keyboard) instead |
Page |
type(int keyCode)
Simulates typing the specified key code while this element has focus, returning the page contained
by this element's window after typing.
|
Page |
type(int keyCode,
boolean shiftKey,
boolean ctrlKey,
boolean altKey)
Deprecated.
as of 2.18, please use
type(Keyboard) instead |
Page |
type(Keyboard keyboard)
Simulates typing the specified
Keyboard while this element has focus, returning the page contained
by this element's window after typing. |
void |
type(String text)
Simulates typing the specified text while this element has focus.
|
void |
type(String text,
boolean shiftKey,
boolean ctrlKey,
boolean altKey)
Deprecated.
as of 2.18, please use
type(Keyboard) instead |
protected void |
typeDone(String newValue)
Called from
DoTypeProcessor. |
blur, click, click, click, cloneNode, dblClick, dblClick, doClickFireChangeEvent, doClickFireClickEvent, doClickStateUpdate, fireEvent, fireEvent, focus, getAttribute, getAttributeNode, getAttributeNodeNS, getAttributeNS, getAttributes, getAttributesMap, getChildElementCount, getChildElements, getElementsByTagName, getElementsByTagNameNS, getEventTargetElement, getFirstElementChild, getId, getLastElementChild, getNextElementSibling, getNodeType, getPreviousElementSibling, getSchemaTypeInfo, getTagName, hasAttribute, hasAttributeNS, hasAttributes, isEmptyXmlTagExpanded, isStateUpdateFirst, mouseDown, mouseDown, mouseMove, mouseMove, mouseOut, mouseOut, mouseOver, mouseOver, mouseUp, mouseUp, namespaces, preventDefault, printOpeningTagContentAsXml, printXml, propagateClickStateUpdateToParent, removeAttributeNode, removeAttributeNS, removeFocus, rightClick, rightClick, setAttribute, setAttributeNodeNS, setIdAttribute, setIdAttributeNode, setIdAttributeNS, toStringgetLocalName, getNamespaceURI, getPrefix, getQualifiedName, processImportNode, setPrefixaddCharacterDataChangeListener, addDomChangeListener, appendChild, asText, asXml, compareDocumentPosition, fireCharacterDataChanged, fireNodeAdded, fireNodeDeleted, getAncestors, getBaseURI, getByXPath, getByXPath, getChildNodes, getChildren, getDescendants, getDomElementDescendants, getEndColumnNumber, getEndLineNumber, getFeature, getFirstByXPath, getFirstByXPath, getFirstChild, getHtmlElementDescendants, getHtmlPageOrNull, getIndex, getLastChild, getNextSibling, getNodeValue, getOwnerDocument, getPage, getParentNode, getPreviousSibling, getReadyState, getScriptableObject, getScriptObject, getStartColumnNumber, getStartLineNumber, getTextContent, getUserData, hasChildNodes, hasFeature, insertBefore, insertBefore, isAncestorOf, isAncestorOfAny, isAttachedToPage, isBlock, isDefaultNamespace, isEqualNode, isSameNode, isSupported, isTrimmedText, lookupNamespaceURI, lookupPrefix, mayBeDisplayed, normalize, notifyIncorrectness, onAddedToDocumentFragment, onAddedToPage, onAllChildrenAddedToPage, printChildrenAsXml, querySelector, querySelectorAll, remove, removeAllChildren, removeCharacterDataChangeListener, removeChild, removeDomChangeListener, replace, replaceChild, setNextSibling, setNodeValue, setParentNode, setPreviousSibling, setReadyState, setScriptableObject, setTextContent, setUserDataclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitappendChild, compareDocumentPosition, getBaseURI, getChildNodes, getFeature, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, getTextContent, getUserData, hasChildNodes, insertBefore, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, normalize, removeChild, replaceChild, setNodeValue, setPrefix, setTextContent, setUserDatapublic static final Short TAB_INDEX_OUT_OF_BOUNDS
getTabIndex()protected HtmlElement(String qualifiedName, SgmlPage page, Map<String,DomAttr> attributes)
qualifiedName - the qualified name of the element type to instantiatepage - the page that contains this elementattributes - a map ready initialized with the attributes for this element, or
null. The map will be stored as is, not copied.public void setAttributeNS(String namespaceURI, String qualifiedName, String attributeValue)
setAttributeNS in interface ElementsetAttributeNS in class DomElementnamespaceURI - the URI that identifies an XML namespacequalifiedName - the qualified name of the attributeattributeValue - the value of the attributepublic Attr setAttributeNode(Attr attribute)
setAttributeNode in interface ElementsetAttributeNode in class DomElementattribute - the attribute to set@Deprecated public final List<HtmlElement> getHtmlElementsByTagNames(List<String> tagNames)
DomElement.getElementsByTagName(String)tagNames - the tag names to match (case-insensitive)@Deprecated public final <E extends HtmlElement> List<E> getHtmlElementsByTagName(String tagName)
DomElement.getElementsByTagName(String), which returns read-only listE - the sub-element typetagName - the tag name to match (case-insensitive)public final void removeAttribute(String attributeName)
removeAttribute in interface ElementremoveAttribute in class DomElementattributeName - the attribute attributeNameprotected void fireHtmlAttributeAdded(HtmlAttributeChangeEvent event)
HtmlAttributeChangeEvent to any
registered HtmlAttributeChangeListeners.
Note that this method recursively calls this element's parent's
fireHtmlAttributeAdded(HtmlAttributeChangeEvent) method.event - the eventaddHtmlAttributeChangeListener(HtmlAttributeChangeListener)protected void fireHtmlAttributeReplaced(HtmlAttributeChangeEvent event)
HtmlAttributeChangeEvent to any
registered HtmlAttributeChangeListeners.
Note that this method recursively calls this element's parent's
fireHtmlAttributeReplaced(HtmlAttributeChangeEvent) method.event - the eventaddHtmlAttributeChangeListener(HtmlAttributeChangeListener)protected void fireHtmlAttributeRemoved(HtmlAttributeChangeEvent event)
HtmlAttributeChangeEvent to any
registered HtmlAttributeChangeListeners.
Note that this method recursively calls this element's parent's
fireHtmlAttributeRemoved(HtmlAttributeChangeEvent) method.event - the eventaddHtmlAttributeChangeListener(HtmlAttributeChangeListener)public String getNodeName()
DomElementgetNodeName in interface NodegetNodeName in class DomElementDomElement.getTagName()public final void setId(String newId)
newId - the new identifier of this elementpublic Short getTabIndex()
TAB_INDEX_OUT_OF_BOUNDS. If this element does not have
a tab index, or its tab index is otherwise invalid, this method returns null.public HtmlElement getEnclosingElement(String tagName)
null if no such element is found.tagName - the name of the tag searched (case insensitive)public HtmlForm getEnclosingForm()
null if this element is not inside
of a form.public HtmlForm getEnclosingFormOrDie() throws IllegalStateException
IllegalStateException.IllegalStateException - if the element is not inside a formpublic void type(String text) throws IOException
text - the text you with to simulate typingIOException - If an IO error occurs@Deprecated public void type(String text, boolean shiftKey, boolean ctrlKey, boolean altKey) throws IOException
type(Keyboard) insteadtext - the text you with to simulate typingshiftKey - true if SHIFT is pressedctrlKey - true if CTRL is pressedaltKey - true if ALT is pressedIOException - If an IO error occurspublic Page type(char c) throws IOException
c - the character you wish to simulate typingIOException - if an IO error occurs@Deprecated public Page type(char c, boolean shiftKey, boolean ctrlKey, boolean altKey) throws IOException
type(Keyboard) insteadc - the character you wish to simulate typingshiftKey - true if SHIFT is pressed during the typingctrlKey - true if CTRL is pressed during the typingaltKey - true if ALT is pressed during the typingWebClient.getCurrentWindow()IOException - if an IO error occurspublic Page type(int keyCode)
KeyboardEvent.DOM_VK_PAGE_DOWN.keyCode - the key code to simulate typingIOException - if an IO error occurspublic Page type(Keyboard keyboard) throws IOException
Keyboard while this element has focus, returning the page contained
by this element's window after typing. Note that it may or may not be the same as the original page,
depending on the JavaScript event handlers, etc. Note also that for some elements, typing XXXXXXXXXXX
submits the enclosed form.keyboard - the keyboardIOException - if an IO error occurs@Deprecated public Page type(int keyCode, boolean shiftKey, boolean ctrlKey, boolean altKey)
type(Keyboard) insteadKeyboardEvent.DOM_VK_PAGE_DOWN.keyCode - the key code wish to simulate typingshiftKey - true if SHIFT is pressed during the typingctrlKey - true if CTRL is pressed during the typingaltKey - true if ALT is pressed during the typingWebClient.getCurrentWindow()IOException - if an IO error occursprotected void doType(char c,
boolean shiftKey,
boolean ctrlKey,
boolean altKey)
c - the character you with to simulate typingshiftKey - true if SHIFT is pressed during the typingctrlKey - true if CTRL is pressed during the typingaltKey - true if ALT is pressed during the typingprotected void doType(int keyCode,
boolean shiftKey,
boolean ctrlKey,
boolean altKey)
KeyboardEvent.DOM_VK_PAGE_DOWN.keyCode - the key code wish to simulate typingshiftKey - true if SHIFT is pressed during the typingctrlKey - true if CTRL is pressed during the typingaltKey - true if ALT is pressed during the typingprotected void typeDone(String newValue)
DoTypeProcessor.newValue - the new valueprotected boolean acceptChar(char c)
c - the charactertrue if it is acceptedprotected boolean isSubmittableByEnter()
true if clicking Enter (ASCII 10, or '\n') should submit the enclosed form (if any).
The default implementation returns false.true if clicking Enter should submit the enclosed form (if any)public final <E extends HtmlElement> E getOneHtmlElementByAttribute(String elementName, String attributeName, String attributeValue) throws ElementNotFoundException
E - the sub-element typeelementName - the name of the element to search forattributeName - the name of the attribute to search forattributeValue - the value of the attribute to search forElementNotFoundException - if no element matches the specified search criteriapublic final <E extends HtmlElement> List<E> getElementsByAttribute(String elementName, String attributeName, String attributeValue)
E - the sub-element typeelementName - the name of the element to search forattributeName - the name of the attribute to search forattributeValue - the value of the attribute to search forpublic final HtmlElement appendChildIfNoneExists(String tagName)
tagName - the tag name of the child to appendpublic final void removeChild(String tagName, int i)
tagName - the tag name of the child to removei - the index of the child to removepublic final boolean hasEventHandlers(String eventName)
true if this element has any JavaScript functions that need to be executed when the
specified event occurs.eventName - the name of the event, such as "onclick" or "onblur", etcpublic final void setEventHandler(String eventName, net.sourceforge.htmlunit.corejs.javascript.Function eventHandler)
eventName - the name of the event, such as "onclick" or "onblur", etceventHandler - a Rhino JavaScript functionpublic final void setEventHandler(String eventName, String jsSnippet)
eventName - Name of event such as "onclick" or "onblur", etcjsSnippet - executable JavaScript codepublic final void removeEventHandler(String eventName)
eventName - Name of the event such as "onclick" or "onblur", etcpublic 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 childNode) throws DOMException
checkChildHierarchy in class DomNodechildNode - the new child node that is being inserted below this nodeDOMException - 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.protected boolean isAttributeCaseSensitive()
isAttributeCaseSensitive in class DomElementfalsepublic final String getLangAttribute()
lang. Refer to the
HTML 4.01
documentation for details on the use of this attribute.lang or an empty string if that attribute isn't definedpublic final String getXmlLangAttribute()
xml:lang. Refer to the
HTML 4.01
documentation for details on the use of this attribute.xml:lang or an empty string if that attribute isn't definedpublic final String getTextDirectionAttribute()
dir. Refer to the
HTML 4.01
documentation for details on the use of this attribute.dir or an empty string if that attribute isn't definedpublic final String getOnClickAttribute()
onclick. Refer to the
HTML 4.01
documentation for details on the use of this attribute.onclick or an empty string if that attribute isn't definedpublic final String getOnDblClickAttribute()
ondblclick. Refer to the
HTML 4.01
documentation for details on the use of this attribute.ondblclick or an empty string if that attribute isn't definedpublic final String getOnMouseDownAttribute()
onmousedown. Refer to the
HTML 4.01
documentation for details on the use of this attribute.onmousedown or an empty string if that attribute isn't definedpublic final String getOnMouseUpAttribute()
onmouseup. Refer to the
HTML 4.01
documentation for details on the use of this attribute.onmouseup or an empty string if that attribute isn't definedpublic final String getOnMouseOverAttribute()
onmouseover. Refer to the
HTML 4.01
documentation for details on the use of this attribute.onmouseover or an empty string if that attribute isn't definedpublic final String getOnMouseMoveAttribute()
onmousemove. Refer to the
HTML 4.01
documentation for details on the use of this attribute.onmousemove or an empty string if that attribute isn't definedpublic final String getOnMouseOutAttribute()
onmouseout. Refer to the
HTML 4.01
documentation for details on the use of this attribute.onmouseout or an empty string if that attribute isn't definedpublic final String getOnKeyPressAttribute()
onkeypress. Refer to the
HTML 4.01
documentation for details on the use of this attribute.onkeypress or an empty string if that attribute isn't definedpublic final String getOnKeyDownAttribute()
onkeydown. Refer to the
HTML 4.01
documentation for details on the use of this attribute.onkeydown or an empty string if that attribute isn't definedpublic final String getOnKeyUpAttribute()
onkeyup. Refer to the
HTML 4.01
documentation for details on the use of this attribute.onkeyup or an empty string if that attribute isn't definedpublic String getCanonicalXPath()
Returns the canonical XPath expression which identifies this node, for instance "/html/body/table[3]/tbody/tr[5]/td[2]/span/a[3]".
WARNING: This sort of automated XPath expression is often quite bad at identifying a node, as it is highly sensitive to changes in the DOM tree.
getCanonicalXPath in class DomNodeDomNode.getByXPath(String)public boolean isDisplayed()
Returns true if this node is displayed and can be visible to the user
(ignoring screen size, scrolling limitations, color, font-size, or overlapping nodes).
NOTE: If CSS is
disabled, this method
does not take this element's style into consideration!
isDisplayed in class DomNodetrue if the node is visible to the user, false otherwiseDomNode.mayBeDisplayed()public HtmlElement.DisplayStyle getDefaultStyleDisplay()
protected final String getSrcAttributeNormalized()
src with all line breaks removed
or an empty string if that attribute isn't defined.protected void detach()
Copyright © 2002–2016 Gargoyle Software Inc.. All rights reserved.