public interface WebElement extends SearchContext, org.openqa.selenium.TakesScreenshot
All method calls will do a freshness check to ensure that the element reference is still valid.
This essentially determines whether or not the element is still attached to the DOM. If this test
fails, then an StaleElementReferenceException
is thrown, and all
future calls to this instance will fail.
Modifier and Type | Method and Description |
---|---|
void |
clear()
If this element is a text entry element, this will clear the value.
|
void |
click()
Click this element.
|
<T extends WebElement> |
findElement(org.openqa.selenium.By by)
Find the first
WebElement using the given method. |
<T extends WebElement> |
findElements(org.openqa.selenium.By by)
Find all elements within the current context using the given mechanism.
|
java.lang.String |
getAttribute(java.lang.String name)
Get the value of the given attribute of the element.
|
java.lang.String |
getCssValue(java.lang.String propertyName)
Get the value of a given CSS property.
|
org.openqa.selenium.Point |
getLocation()
Where on the page is the top left-hand corner of the rendered element?
|
org.openqa.selenium.Rectangle |
getRect() |
org.openqa.selenium.Dimension |
getSize()
What is the width and height of the rendered element?
|
java.lang.String |
getTagName()
Get the tag name of this element.
|
java.lang.String |
getText()
Get the visible (i.e. not hidden by CSS) innerText of this element, including sub-elements,
without any leading or trailing whitespace.
|
boolean |
isDisplayed()
Is this element displayed or not?
|
boolean |
isEnabled()
Is the element currently enabled or not?
|
boolean |
isSelected()
Determine whether or not this element is selected or not.
|
void |
sendKeys(java.lang.CharSequence... keysToSend)
Use this method to simulate typing into an element, which may set its value.
|
void |
submit()
If this current element is a form, or an element within a form, then this will be submitted to
the remote server.
|
void click()
StaleElementReferenceException
- If the element no
longer exists as initially definedvoid submit()
NoSuchElementException
- If the given element is not within a formvoid sendKeys(java.lang.CharSequence... keysToSend)
keysToSend
- character sequence to send to the elementvoid clear()
sendKeys(CharSequence...)
with the backspace key. To ensure
you get a change event, consider following with a call to sendKeys(CharSequence...)
with the tab key.java.lang.String getTagName()
"input"
for the element <input name="foo" />
.java.lang.String getAttribute(java.lang.String name)
More exactly, this method will return the value of the property with the given name, if it exists. If it does not, then the value of the attribute with the given name is returned. If neither exists, null is returned.
The "style" attribute is converted as best can be to a text representation with a trailing semi-colon.
The following are deemed to be "boolean" attributes, and will return either "true" or null:
async, autofocus, autoplay, checked, compact, complete, controls, declare, defaultchecked, defaultselected, defer, disabled, draggable, ended, formnovalidate, hidden, indeterminate, iscontenteditable, ismap, itemscope, loop, multiple, muted, nohref, noresize, noshade, novalidate, nowrap, open, paused, pubdate, readonly, required, reversed, scoped, seamless, seeking, selected, truespeed, willvalidate
Finally, the following commonly mis-capitalized attribute/property names are evaluated as expected:
name
- The name of the attribute.boolean isSelected()
boolean isEnabled()
java.lang.String getText()
<T extends WebElement> java.util.List<T> findElements(org.openqa.selenium.By by)
findElements
in interface SearchContext
by
- The locating mechanism to useWebElement
s, or an empty list if nothing matches.By
,
WebDriver.Timeouts
<T extends WebElement> T findElement(org.openqa.selenium.By by)
WebElement
using the given method. See the note in
findElements(By)
about finding via XPath.
This method is affected by the 'implicit wait' times in force at the time of execution.
The findElement(..) invocation will return a matching row, or try again repeatedly until
the configured timeout is reached.
findElement should not be used to look for non-present elements, use findElements(By)
and assert zero length response instead.findElement
in interface SearchContext
by
- The locating mechanismNoSuchElementException
- If no matching elements are foundBy
,
WebDriver.Timeouts
boolean isDisplayed()
org.openqa.selenium.Point getLocation()
org.openqa.selenium.Dimension getSize()
org.openqa.selenium.Rectangle getRect()
java.lang.String getCssValue(java.lang.String propertyName)
propertyName
- the css property name of the element