public class Element extends Object implements org.openqa.selenium.WebElement, Iterable<Element>
<elementName attributename='attributeValue'>
). Elements typically form a tree structure, where an element may also have one or more children (which can be other Elements, or Nodes such as text, comments, etc), and has a single parent. When two elements share the same parent, they are said to be sibling elements with respect to each other. The term "ancestor" refers to any element that rests at or above the level of the element's parent, and the term "descendant" refers to any element at or beneath the level of the element's child/children.Modifier and Type | Method and Description |
---|---|
void |
clear() |
void |
click() |
Elements |
findEach(String query)
Searches descendant elements and retrieves elements that were found to match the query, however for every matching element is found, the search does not continue into that element's descendants.
|
org.openqa.selenium.WebElement |
findElement(org.openqa.selenium.By by) |
List<org.openqa.selenium.WebElement> |
findElements(org.openqa.selenium.By arg0) |
Elements |
findEvery(String query)
Searches all descendant elements and retrieves all elements that were found to match the query.
|
Element |
findFirst(String query)
Searches all descendant elements and retrieves the first one found to match the query.
|
String |
getAt(String attributeName)
Returns the attribute value for the specified (case insensitive) attribute name and throws a NotFound Exception if no such attribute name exists or if the attribute value is null; relative URLs are expanded into absolute URLs.
|
String |
getAtStr(String attributeName)
Returns the attribute value for the specified (case insensitive) attribute name and returns an empty String no such attribute name exists or if no value exists for the specified attribute name; relative URLs are expanded into absolute URLs.
|
String |
getAttribute(String name)
Returns the value for the specified (case insensitive) attribute name OR property name, which may be a null value; all relative URLS are expanded to absolute URLS before being returned.
|
List<String> |
getAttributeNames()
Retrieves a list of the attribute names.
|
List<Element> |
getChildElements()
Returns a list of child Elements, or an empty list if no child elements exist.
|
List<Node> |
getChildNodes()
Returns a list of child nodes, or an empty list if no child nodes exist.
|
String |
getChildText()
Returns a concatenation of all immediate child text nodes (whether or not they are hidden by CSS), or returns an empty String if none exist.
|
String |
getChildText(String separator,
boolean collapseWhitespace)
Returns a concatenation of all immediate child text nodes (whether or not they are hidden by CSS), or returns an empty String if none exist.
|
String |
getCssValue(String arg0) |
Elements |
getEach(String query)
Searches child elements (not all descendants) and retrieves those that
were found to match the query.
|
Element |
getElement(int index)
Returns the child element at the position denoted by the specified index.
|
Element |
getFirst(String query)
Searches only child elements (not all descendants) and retrieves the first child element that was found to match the query.
|
org.openqa.selenium.Point |
getLocation() |
Element |
getParent()
Returns the parent element or null if a parent element does not exist.
|
org.openqa.selenium.Rectangle |
getRect() |
Element |
getRoot()
Return the ancestor Element who's parent is null (ie, the root element).
|
<X> X |
getScreenshotAs(org.openqa.selenium.OutputType<X> arg0) |
org.openqa.selenium.Dimension |
getSize() |
String |
getTagName() |
String |
getText()
Returns the concatentation of all visible text within this element, including all the visible text of all descendants; text that is not visible due to CSS rules is excluded.
|
String |
getTextContent() |
String |
getTextContent(String separator,
boolean includeComments,
boolean includeScripts) |
String |
innerHTML()
Returns a String representation of this element's children/descendant nodes as HTML.
|
String |
innerHTML(int indent) |
void |
innerHTML(String html)
Replaces the contents of this element (ie the descendant nodes) with the specified HTML.
|
boolean |
isDisplayed() |
boolean |
isEnabled() |
boolean |
isSelected() |
Iterator<Element> |
iterator()
Returns an iterator over the child elements.
|
Element |
nextElementSibling()
Returns the next element that is a sibling (shares the same parent), or null if none exists.
|
Node |
nextNodeSibling()
Returns the next node that is a sibling (shares the name parent) or returns null if no such sibling exists.
|
String |
outerHTML()
Returns an HTML representation of this element (including its children/descendant nodes).
|
String |
outerHTML(int indent) |
void |
outerHTML(String html)
Replaces this element and its descendants in the DOM with the specified HTML.
|
Element |
previousElementSibling()
Returns the previous element that is a sibling (shares the same parent), or null if none exists.
|
Node |
previousNodeSibling()
Returns the previous node that is a sibling (shares the name parent) or returns null if no such sibling exists.
|
void |
remove()
Removes this element (and its descendants) from the DOM.
|
void |
removeAttribute(String attName)
Removes the attribute that has the specified attribute name.
|
void |
sendKeys(CharSequence... arg0) |
void |
setAttribute(String attName,
String attValue)
Sets the attribute of the specified name to the specified value.
|
void |
submit() |
Node |
toNode()
Returns this element cast to type Node.
|
String |
toString()
Returns a string representation of this element as an HTML tag, not including children or its counterpart closing tag.
|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
forEach, spliterator
public Elements findEvery(String query)
query
- a query that has the general form <tagnameRegex attributeName="attributeValueRegex">childTextRegex
where multiple attributes are allowed. In order for the query to match against an element, the tagnameRegex, attribute name, attributeValueRegex and immediateTextRegex must match if they are specified.Matcher.find()
.public Elements findEach(String query)
query
- a query that has the general form <tagnameRegex attributeName="attributeValueRegex">childTextRegex
where multiple attributes are allowed. In order for the query to match against an element, the tagnameRegex, attribute name, attributeValueRegex and immediateTextRegex must match if they are specified.Matcher.find()
.public Elements getEach(String query)
query
- a query that has the general form
<tagnameRegex attributeName="attributeValueRegex">childTextRegex
where multiple attributes are allowed. In order for the query to
match against an element, the tagnameRegex, attribute name,
attributeValueRegex and immediateTextRegex must match if they are
specified.Matcher.find()
.public Element findFirst(String query) throws NotFound
query
- a query that has the general form <tagnameRegex attributeName="attributeValueRegex">childTextRegex
where multiple attributes are allowed. In order for the query to match against an element, the tagnameRegex, attribute name, attributeValueRegex and immediateTextRegex must match if they are specified.Matcher.find()
.NotFound
public Element getFirst(String query) throws NotFound
query
- a query that has the general form <tagnameRegex attributeName="attributeValueRegex">childTextRegex
where multiple attributes are allowed. In order for the query to match against an element, the tagnameRegex, attribute name, attributeValueRegex and immediateTextRegex must match if they are specified.Matcher.find()
.NotFound
public void clear()
clear
in interface org.openqa.selenium.WebElement
WebElement.clear()
public void click()
click
in interface org.openqa.selenium.WebElement
WebElement.click()
public org.openqa.selenium.WebElement findElement(org.openqa.selenium.By by)
findElement
in interface org.openqa.selenium.SearchContext
findElement
in interface org.openqa.selenium.WebElement
WebElement.findElement(By)
public List<String> getAttributeNames()
public String getAttribute(String name)
getAttribute
in interface org.openqa.selenium.WebElement
WebElement.getAttribute(String)
public String getAt(String attributeName) throws NotFound
attributeName
- case insensitive attribute name.NotFound
public String getAtStr(String attributeName)
attributeName
- case insensitive attribute name.public <X> X getScreenshotAs(org.openqa.selenium.OutputType<X> arg0) throws org.openqa.selenium.WebDriverException
getScreenshotAs
in interface org.openqa.selenium.TakesScreenshot
org.openqa.selenium.WebDriverException
TakesScreenshot.getScreenshotAs(OutputType)
public List<org.openqa.selenium.WebElement> findElements(org.openqa.selenium.By arg0)
findElements
in interface org.openqa.selenium.SearchContext
findElements
in interface org.openqa.selenium.WebElement
WebElement.findElements(By)
public String getCssValue(String arg0)
getCssValue
in interface org.openqa.selenium.WebElement
WebElement.getCssValue(String)
public org.openqa.selenium.Point getLocation()
getLocation
in interface org.openqa.selenium.WebElement
WebElement.getLocation()
public org.openqa.selenium.Rectangle getRect()
getRect
in interface org.openqa.selenium.WebElement
WebElement.getRect()
public org.openqa.selenium.Dimension getSize()
getSize
in interface org.openqa.selenium.WebElement
WebElement.getSize()
public String getTagName()
getTagName
in interface org.openqa.selenium.WebElement
WebElement.getTagName()
public String getText()
getText
in interface org.openqa.selenium.WebElement
WebElement.getText()
public String getChildText()
public String getChildText(String separator, boolean collapseWhitespace)
separator
- the separator to use between each text node when they are joined.collapseWhitespace
- whether multiple adjacent whitespace characters should be collapsed into a single whitespacepublic String getTextContent()
public String getTextContent(String separator, boolean includeComments, boolean includeScripts)
public boolean isDisplayed()
isDisplayed
in interface org.openqa.selenium.WebElement
WebElement.isDisplayed()
public boolean isEnabled()
isEnabled
in interface org.openqa.selenium.WebElement
WebElement.isEnabled()
public boolean isSelected()
isSelected
in interface org.openqa.selenium.WebElement
WebElement.isSelected()
public void sendKeys(CharSequence... arg0)
sendKeys
in interface org.openqa.selenium.WebElement
WebElement.sendKeys(CharSequence...)
public void submit()
submit
in interface org.openqa.selenium.WebElement
WebElement.submit()
public String toString()
public void innerHTML(String html)
html
- html content to be inserted as a child or children to this element.public String innerHTML()
public String innerHTML(int indent)
public String outerHTML()
public String outerHTML(int indent)
public void outerHTML(String html)
html
- html content to be inserted in place of this element.public Element getElement(int index) throws ArrayIndexOutOfBoundsException
index
- the index of the child element, where the first child has index 0.ArrayIndexOutOfBoundsException
public Element getParent()
public Element nextElementSibling()
public Element previousElementSibling()
public void remove()
public Element getRoot()
public List<Element> getChildElements()
public void setAttribute(String attName, String attValue)
attName
- the name of the target attribute.attValue
- the value to set for the attribute.public void removeAttribute(String attName)
public Node toNode()
public Node nextNodeSibling()
public Node previousNodeSibling()