|
||||||||||
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.DomElement
com.gargoylesoftware.htmlunit.html.HtmlElement
public abstract class HtmlElement
An abstract wrapper for html elements
Nested Class Summary | |
---|---|
protected class |
HtmlElement.ChildElementsIterator
an iterator over the HtmlElement children |
static class |
HtmlElement.MapEntryWrappingIterator
Deprecated. This class is no longer used since attributes are now represented by HtmlAttr. |
Nested classes/interfaces inherited from class com.gargoylesoftware.htmlunit.html.DomNode |
---|
DomNode.ChildIterator, DomNode.DescendantElementsIterator |
Field Summary | |
---|---|
static String |
ATTRIBUTE_NOT_DEFINED
Constant meaning that the specified attribute was not defined. |
static String |
ATTRIBUTE_VALUE_EMPTY
Constant meaning that the specified attribute was found but its value was empty. |
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). |
Fields inherited from class com.gargoylesoftware.htmlunit.html.DomNode |
---|
ATTRIBUTE_NODE, COMMENT_NODE, DOCUMENT_NODE, ELEMENT_NODE, PROPERTY_ELEMENT, READY_STATE_COMPLETE, READY_STATE_INTERACTIVE, READY_STATE_LOADED, READY_STATE_LOADING, READY_STATE_UNINITIALIZED, TEXT_NODE |
Constructor Summary | |
---|---|
protected |
HtmlElement(String namespaceURI,
String qualifiedName,
HtmlPage htmlPage,
Map attributes)
Creates an instance. |
Method Summary | |
---|---|
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 |
assertNotEmpty(String description,
String string)
Assert that the specified string is not empty. |
void |
blur()
Remove focus from this element. |
DomNode |
cloneDomNode(boolean deep)
Overrides DomNode.cloneDomNode(boolean) so clone gets its own Map of attributes. |
DomNode |
cloneNode(boolean deep)
Deprecated. This method conflicts with the W3C DOM API since the return values are different. Use cloneDomNode(boolean) instead. |
ScriptResult |
fireEvent(com.gargoylesoftware.htmlunit.javascript.host.Event event)
Fire the event on the element. |
ScriptResult |
fireEvent(String eventType)
Shortcut for fireEvent(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. |
void |
focus()
Set the focus to this element. |
String |
getAttribute(String attributeName)
Return the value of the attribute specified by name or an empty string. |
Iterator |
getAttributeEntriesIterator()
|
String |
getAttributeNS(String namespaceURI,
String localName)
Return the value of the attribute specified by namespace and local name or an empty string. |
String |
getAttributeValue(String attributeName)
Return the value of the specified attribute or an empty string. |
Iterator |
getChildElementsIterator()
|
HtmlElement |
getEnclosingElement(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(String eventName)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK. Return a Function to be executed when a given event occurs. |
HtmlElement |
getHtmlElementById(String id)
Return the html element with the specified id. |
List |
getHtmlElementsByAttribute(String elementName,
String attributeName,
String attributeValue)
Search by the specified criteria and return all the HtmlElement that are found |
List |
getHtmlElementsByTagName(String tagName)
Given a list of tag names, return the html elements that correspond to any matching element |
List |
getHtmlElementsByTagNames(List acceptableTagNames)
Given a list of tag names, return the html elements that correspond to any matching element |
String |
getId()
|
String |
getNodeName()
Get the name for the current node. |
short |
getNodeType()
Get the type of the current node. |
HtmlElement |
getOneHtmlElementByAttribute(String elementName,
String attributeName,
String attributeValue)
Search by the specified criteria and return the first HtmlElement that is found |
Short |
getTabIndex()
Returns this element's tab index, if it has one. |
String |
getTagName()
Return the tag name of this element. |
boolean |
hasAttribute(String attributeName)
Return whether the attribute specified by name has a value. |
boolean |
hasAttributeNS(String namespaceURI,
String localName)
Return whether the attribute specified by namespace and local name has a value. |
boolean |
hasAttributes()
Return whether this node has any attributes. |
boolean |
hasHtmlElementWithId(String id)
Return true if there is a element with the specified id. |
boolean |
isAttributeDefined(String attributeName)
Return true if the specified attribute has been defined. |
protected boolean |
isEmptyXmlTagExpanded()
Indicates if a node without children should be written in expanded form as xml (i.e. |
protected boolean |
isSubmittableByEnter()
Returns true if clicking Enter (ASCII 10, or '\n') should submit the enclosed form (if any). |
void |
keyDown(int keyCode)
Deprecated. use type(char) instead |
void |
keyDown(int keyCode,
boolean shiftKey,
boolean ctrlKey,
boolean altKey)
Deprecated. use type(char, boolean, boolean, boolean) instead |
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. |
protected void |
notImplemented()
Throw an exception. |
protected void |
preventDefault()
This method is called if the current fired event is canceled by preventDefault() in FireFox, or by returning false in Internet Explorer. |
protected void |
printOpeningTagContentAsXml(PrintWriter printWriter)
Prints the content between "<" and ">" (or "/>") in the output of the tag name and its attributes in xml format. |
protected void |
printXml(String indent,
PrintWriter printWriter)
recursively write the XML data for the node tree starting at node |
void |
removeAttribute(String attributeName)
Removes an attribute specified by name from this element. |
void |
removeAttributeNS(String namespaceURI,
String localName)
Removes an attribute specified by namespace and local 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. |
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 |
setAttribute(String attributeName,
String attributeValue)
Set the value of the attribute specified by name. |
void |
setAttributeNS(String namespaceURI,
String qualifiedName,
String attributeValue)
Set the value of the attribute specified by namespace and qualified name. |
void |
setAttributeValue(String attributeName,
String attributeValue)
Set the value of the specified attribute. |
void |
setAttributeValue(String namespaceURI,
String qualifiedName,
String attributeValue)
Set the value of the specified attribute. |
void |
setEventHandler(String eventName,
org.mozilla.javascript.Function eventHandler)
INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK. Register a 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)
Set the identifier this element. |
String |
toString()
Return a string representation of this object |
Page |
type(char c)
Simulates typing the specified character while this element has focus. |
Page |
type(char c,
boolean shiftKey,
boolean ctrlKey,
boolean altKey)
Simulates typing the specified character while this element has focus. |
void |
type(String text)
Simulates typing the specified text while this element has focus. |
void |
type(String text,
boolean shiftKey,
boolean ctrlKey,
boolean altKey)
Simulates typing the specified text while this element has focus. |
Methods inherited from class com.gargoylesoftware.htmlunit.html.DomNamespaceNode |
---|
getLocalName, getNamespaceURI, getPrefix, getQualifiedName, setPrefix |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String ATTRIBUTE_NOT_DEFINED
public static final String ATTRIBUTE_VALUE_EMPTY
public static final Short TAB_INDEX_OUT_OF_BOUNDS
getTabIndex()
Constructor Detail |
---|
protected HtmlElement(String namespaceURI, String qualifiedName, HtmlPage htmlPage, Map attributes)
namespaceURI
- the URI that identifies an XML namespace.qualifiedName
- The qualified name of the element type to instantiatehtmlPage
- 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.Method Detail |
---|
public DomNode cloneNode(boolean deep)
cloneDomNode(boolean)
instead.
DomNode.cloneNode(boolean)
so clone gets its own Map of attributes.
Make a clone of this node
cloneNode
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 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 final String getAttribute(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 String getAttributeNS(String namespaceURI, String localName)
ATTRIBUTE_NOT_DEFINED
if the attribute wasn't specified or ATTRIBUTE_VALUE_EMPTY
if the
attribute was specified but it was empty.
namespaceURI
- the URI that identifies an XML namespace.localName
- The name within the namespace.
ATTRIBUTE_NOT_DEFINED
or ATTRIBUTE_VALUE_EMPTY
public boolean hasAttributes()
hasAttributes
in class DomNode
public final boolean hasAttribute(String attributeName)
attributeName
- the name of the attribute
public final boolean hasAttributeNS(String namespaceURI, String localName)
namespaceURI
- the URI that identifies an XML namespace.localName
- The name within the namespace.
public final String getAttributeValue(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 void setAttribute(String attributeName, String attributeValue)
attributeName
- the name of the attributeattributeValue
- The value of the attributepublic final void setAttributeNS(String namespaceURI, String qualifiedName, String attributeValue)
namespaceURI
- the URI that identifies an XML namespace.qualifiedName
- The qualified name (prefix:local) of the attribute.attributeValue
- The value of the attributepublic final void setAttributeValue(String attributeName, String attributeValue)
attributeName
- the name of the attributeattributeValue
- The value of the attributepublic void setAttributeValue(String namespaceURI, String qualifiedName, String attributeValue)
namespaceURI
- the URI that identifies an XML namespace.qualifiedName
- The qualified name of the attributeattributeValue
- The value of the attributepublic final void removeAttribute(String attributeName)
attributeName
- the attribute attributeNamepublic final void removeAttributeNS(String namespaceURI, String localName)
namespaceURI
- the URI that identifies an XML namespace.localName
- The name within the namespace.protected void fireHtmlAttributeAdded(HtmlAttributeChangeEvent event)
event
- The event.protected void fireHtmlAttributeReplaced(HtmlAttributeChangeEvent event)
event
- The event.protected void fireHtmlAttributeRemoved(HtmlAttributeChangeEvent event)
event
- The event.public boolean isAttributeDefined(String attributeName)
attributeName
- The attribute to check
public 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 String getTagName()
public short getNodeType()
DomNode
getNodeType
in class DomNode
public String getNodeName()
DomNode
getNodeName
in class DomNode
getTagName()
,public final String getId()
public final void setId(String newId)
newId
- The new identifier of this element.public 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)
tagName
- the name of the tag searched (case insensitive)
public HtmlForm getEnclosingForm()
public HtmlForm getEnclosingFormOrDie() throws IllegalStateException
IllegalStateException
- If the element is not within a form.public void keyDown(int keyCode)
type(char)
instead
keyCode
- the key you wish to presspublic void keyDown(int keyCode, boolean shiftKey, boolean ctrlKey, boolean altKey)
type(char, boolean, boolean, boolean)
instead
keyCode
- the key you wish to pressshiftKey
- true if SHIFT is pressedctrlKey
- true if CTRL is pressedaltKey
- true if ALT is pressedpublic void type(String text) throws IOException
text
- the text you with to simulate typing
IOException
- If an IO error occurspublic void type(String text, boolean shiftKey, boolean ctrlKey, boolean altKey) throws IOException
text
- the text you with to simulate typingshiftKey
- true if SHIFT is pressedctrlKey
- true if CTRL is pressedaltKey
- true if ALT is pressed
IOException
- If an IO error occurspublic Page type(char c) throws IOException
c
- the character you with to simulate typing
IOException
- If an IO error occurspublic Page type(char c, boolean shiftKey, boolean ctrlKey, boolean altKey) throws IOException
c
- the character you with to simulate typingshiftKey
- true if SHIFT is pressedctrlKey
- true if CTRL is pressedaltKey
- true if ALT is pressed
IOException
- If an IO error occursprotected boolean isSubmittableByEnter()
protected void printXml(String indent, PrintWriter printWriter)
node
printXml
in class DomNode
indent
- white space to indent child nodesprintWriter
- writer where child nodes are writtenprotected boolean isEmptyXmlTagExpanded()
false
protected void printOpeningTagContentAsXml(PrintWriter printWriter)
printWriter
- the writer to print inpublic String toString()
toString
in class Object
protected final void notImplemented()
protected final void assertNotEmpty(String description, String string) throws IllegalArgumentException
description
- The description to pass into the exception if this string is emptystring
- The string to check
IllegalArgumentException
- If the string is emptypublic final HtmlElement getOneHtmlElementByAttribute(String elementName, String attributeName, 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 HtmlElement getHtmlElementById(String id) throws ElementNotFoundException
id
- The id value to search by
ElementNotFoundException
- If no element was found that matches the idpublic boolean hasHtmlElementWithId(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 final List getHtmlElementsByAttribute(String elementName, String attributeName, String attributeValue)
elementName
- The name of the elementattributeName
- The name of the attributeattributeValue
- The value of the attribute
public final List getHtmlElementsByTagNames(List acceptableTagNames)
acceptableTagNames
- The list of tag names to search by.
public final List getHtmlElementsByTagName(String tagName)
tagName
- the tag name to match
public final HtmlElement appendChildIfNoneExists(String tagName)
tagName
- the tag name of the child to append
public final void removeChild(String tagName, int i)
tagName
- the tag name of the child to removei
- the index of the child to removepublic final Iterator getChildElementsIterator()
public final org.mozilla.javascript.Function getEventHandler(String eventName)
getEventHandler
in class DomNode
eventName
- Name of event such as "onclick" or "onblur", etc.
public final void setEventHandler(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(String eventName, String jsSnippet)
setEventHandler
in class DomNode
eventName
- Name of event such as "onclick" or "onblur", etc.jsSnippet
- executable javascript codepublic final void removeEventHandler(String eventName)
removeEventHandler
in class DomNode
eventName
- Name of the event such as "onclick" or "onblur", etc.public void addHtmlAttributeChangeListener(HtmlAttributeChangeListener listener)
listener
- the attribute change listener to be added.removeHtmlAttributeChangeListener(HtmlAttributeChangeListener)
public void removeHtmlAttributeChangeListener(HtmlAttributeChangeListener listener)
listener
- the attribute change listener to be removed.addHtmlAttributeChangeListener(HtmlAttributeChangeListener)
public ScriptResult fireEvent(String eventType)
fireEvent(Event)
.
eventType
- the event type (like "load", "click")
null
if nothing is executed.public ScriptResult fireEvent(com.gargoylesoftware.htmlunit.javascript.host.Event event)
event
- the event to fire.
null
if nothing is executed.protected void preventDefault()
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 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 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 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 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 void blur()
public void focus()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |