public interface Node extends EventTarget, SearchContext
| Modifier and Type | Method and Description |
|---|---|
boolean |
appendChild(Node childNode)
Adds the given
node as a child of the current node to the end of its children list. |
java.util.List<Node> |
children()
Returns an immutable list of all children of this node.
|
void |
click()
Simulates a click on the node.
|
void |
close()
Closes this node.
|
java.util.Set<DocumentPosition> |
compareDocumentPosition(Node otherNode)
Compares position of the current node against another node in a DOM tree.
|
Document |
document()
Returns the
Document instance of this node. |
XPathResult |
evaluate(java.lang.String expression)
Evaluates the given XPath
expression for the node and returns the XPathResult
of the XPathResultType.ANY type. |
XPathResult |
evaluate(java.lang.String expression,
XPathResultType type)
Evaluates the given XPath
expression for the node and returns the XPathResult
object of the given type. |
boolean |
insertChild(Node node,
Node beforeNode)
Inserts the given
node before the given beforeNode as a child of the current
node. |
java.util.Optional<Node> |
nextSibling()
Returns an
Optional that contains the next node in the document tree if such a node
exists, otherwise returns an empty Optional. |
java.lang.String |
nodeName()
Returns a string that represents the node name in the UTF8 format.
|
java.lang.String |
nodeValue()
Returns a string that represents the node value.
|
void |
nodeValue(java.lang.String value)
Updates the node value with the given new
value. |
java.util.Optional<Node> |
parent()
Returns an
Optional that contains the parent of this node. |
java.util.Optional<Node> |
previousSibling()
Returns an
Optional that contains the previous node in the document tree if such a
node exists, otherwise returns an empty Optional. |
boolean |
removeChild(Node childNode)
Removes the given
childNode of the current node from the DOM. |
boolean |
replaceChild(Node newNode,
Node oldNode)
Replaces the given child
oldNode of the current node with the given newNode. |
java.lang.String |
textContent()
Returns the text content of the current node and its descendants.
|
void |
textContent(java.lang.String textContent)
Removes all the current node children and replaces them with a single text node with the
given
textContent. |
NodeType |
type()
Returns the node type.
|
java.lang.String |
xPath()
Returns a string that represents XPath to the current Node or an empty string if it is not
available.
|
addEventListener, dispatch, eventListeners, removeEventListenerfindElementByClassName, findElementByCssSelector, findElementById, findElementByName, findElementByTagName, findElementsByClassName, findElementsByCssSelector, findElementsById, findElementsByName, findElementsByTagNameDocument document()
Document instance of this node.ObjectClosedException - when this node is closedjava.lang.String nodeName()
The returned values for different types of nodes are:
| Node type | Returned value | |
|---|---|---|
NodeType.ELEMENT_NODE |
The element tag name.
For DOM trees which represent HTML documents, the returned value is always capitalized. The tag names of elements in an XML DOM tree are returned in the same case in which they're written in the original XML file. |
|
NodeType.ATTRIBUTE_NODE |
The attribute name | |
NodeType.TEXT_NODE |
"#text" | |
NodeType.C_DATA_SECTION_NODE |
"#cdata-section" | |
| The entity name | ||
NodeType.PROCESSING_INSTRUCTIONS_NODE |
The value of the target attribute |
|
NodeType.COMMENT_NODE |
"#comment" | |
NodeType.DOCUMENT_NODE |
"#document" | |
NodeType.DOCUMENT_TYPE_NODE |
The document type name, for example "html" for <!DOCTYPE HTML> |
|
NodeType.DOCUMENT_FRAGMENT_NODE |
"#document-fragment" |
ObjectClosedException - when this node is closedjava.lang.String nodeValue()
The returned values for different types of nodes are:
| Node type | Returned value | |
|---|---|---|
NodeType.ELEMENT_NODE |
null | |
NodeType.ATTRIBUTE_NODE |
The attribute value | |
NodeType.TEXT_NODE |
The content of the text node | |
NodeType.C_DATA_SECTION_NODE |
The content of the CDATA Section | |
NodeType.PROCESSING_INSTRUCTIONS_NODE |
The entire node content excluding the target | |
NodeType.COMMENT_NODE |
The content of the comment | |
NodeType.DOCUMENT_NODE |
null | |
NodeType.DOCUMENT_TYPE_NODE |
null | |
NodeType.DOCUMENT_FRAGMENT_NODE |
null |
ObjectClosedException - when this instance is closedvoid nodeValue(java.lang.String value)
value.
This method does nothing, if it is invoked for the node of one of the following types:
NodeType.ELEMENT_NODE, NodeType.DOCUMENT_NODE, NodeType.DOCUMENT_TYPE_NODE, NodeType.DOCUMENT_FRAGMENT_NODE.
value - a new node valueObjectClosedException - when this node is closednodeValue()NodeType type()
ObjectClosedException - when this node is closedjava.util.Optional<Node> parent()
Optional that contains the parent of this node. If there is no such node,
for example when this node is the document or it does not belong to the DOM tree, returns an
empty Optional.ObjectClosedException - when this node is closedjava.util.List<Node> children()
Please note, that this method should be invoked every time in case of need to retrieve an actual children list.
ObjectClosedException - when this node is closedjava.util.Optional<Node> nextSibling()
Optional that contains the next node in the document tree if such a node
exists, otherwise returns an empty Optional.ObjectClosedException - when this node is closedjava.util.Optional<Node> previousSibling()
Optional that contains the previous node in the document tree if such a
node exists, otherwise returns an empty Optional.ObjectClosedException - when this node is closedvoid click()
ObjectClosedException - when this node is closedboolean insertChild(Node node, Node beforeNode)
node before the given beforeNode as a child of the current
node. The new node can be an existing node in the document, or you can create and insert a
new node. If the node is existing node, it will be moved to a new location in the
document.node - the node to insertbeforeNode - the node before which the node will be insertedtrue if the given node was successfully insertedObjectClosedException - when this node is closedboolean replaceChild(Node newNode, Node oldNode)
oldNode of the current node with the given newNode.
The new node can be an existing node in the document, or you can create and insert a new
node. If the newNode is existing node, it will be moved to a new location in the
document.newNode - the new node to replace the oldNodeoldNode - the existing node to be replacedtrue if the given oldNode was successfully replacedObjectClosedException - when this node is closedboolean removeChild(Node childNode)
childNode of the current node from the DOM. The removed childNode still exists, but is no longer part of the DOM. You can reuse the removed node
later in your code via the childNode object reference.childNode - the existing node to be removedtrue if the given node was successfully removedObjectClosedException - when this node is closedboolean appendChild(Node childNode)
node as a child of the current node to the end of its children list.
The new node could be an existing node in the document, or you can create and add a new node.
If the node is existing node, it will be moved to a new location in the document.childNode - the node to appendtrue if the given node was successfully insertedObjectClosedException - when this node is closedjava.lang.String textContent()
NodeType.DOCUMENT_NODE or NodeType.DOCUMENT_TYPE_NODE.
NodeType.C_DATA_SECTION_NODE, NodeType.COMMENT_NODE, NodeType.PROCESSING_INSTRUCTIONS_NODE, or NodeType.TEXT_NODE.
ObjectClosedException - when this node is closedvoid textContent(java.lang.String textContent)
textContent.textContent - the new text content of the current nodeObjectClosedException - when this node is closedXPathResult evaluate(java.lang.String expression)
expression for the node and returns the XPathResult
of the XPathResultType.ANY type.expression - a string representing the XPath to be evaluatedjava.lang.IllegalArgumentException - when expression is emptyXPathException - when this method failed to evaluate the given expressionObjectClosedException - when this node is closedevaluate(String, XPathResultType)XPathResult evaluate(java.lang.String expression, XPathResultType type)
expression for the node and returns the XPathResult
object of the given type.expression - a string representing the XPath to be evaluatedtype - type of XPathResult to returnjava.lang.IllegalArgumentException - when expression is empty or blankXPathException - when this method failed to evaluate the given expression and
return a result of the given typeObjectClosedException - when this node is closedXPathResultTypejava.lang.String xPath()
For the document() this method returns an empty string.
ObjectClosedException - when this node is closedjava.util.Set<DocumentPosition> compareDocumentPosition(Node otherNode)
otherNode - the node to be compared to the current nodeotherNode parameter
relates to the position of the current nodeObjectClosedException - when this node is closedvoid close()
This method makes the underlying Blink node eligible for garbage collection, but does not guarantee that it will be destroyed. That is, if the node is still attached to the DOM tree, you can obtain it again through the DOM or JavaScript API.
Use this method to make unused nodes garbage collectable when you create, attach and detach a large number of nodes to/from the DOM tree on the same web page without reloading, closing the browser, or navigating to another web page.
All nodes are closed automatically when you perform a navigation, reload the web page, or close the browser.