public interface WebElement extends SearchContext, 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 form entry element, this will reset its value.
|
void |
click()
Click this element.
|
WebElement |
findElement(By by)
Find the first
WebElement using the given method. |
java.util.List<WebElement> |
findElements(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.
|
Point |
getLocation()
Where on the page is the top left-hand corner of the rendered element?
|
Rectangle |
getRect() |
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.
|
boolean |
isDisplayed()
Is this element displayed or not? This method avoids the problem of having to parse an
element's "style" attribute.
|
boolean |
isEnabled()
Is the element currently enabled or not? This will generally return true for everything but
disabled input elements.
|
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.
|
getScreenshotAs
void click()
Note that if click() is done by sending a native event (which is the default on most browsers/platforms) then the method will _not_ wait for the next page to load and the caller should verify that themselves.
There are some preconditions for an element to be clicked. The element must be visible and it must have a height and width greater then 0.
See W3C WebDriver specification for more details.
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)
See W3C WebDriver specification for more details.
keysToSend
- character sequence to send to the elementjava.lang.IllegalArgumentException
- if keysToSend is nullvoid clear()
See W3C WebDriver specification and HTML specification for more details.
java.lang.String getTagName()
"input"
for the element <input name="foo" />
.
See W3C WebDriver specification for more details.
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:
See W3C WebDriver specification for more details.
name
- The name of the attribute.boolean isSelected()
See W3C WebDriver specification for more details.
boolean isEnabled()
See W3C WebDriver specification for more details.
java.lang.String getText()
See W3C WebDriver specification for more details.
java.util.List<WebElement> findElements(By by)
See W3C WebDriver specification for more details.
findElements
in interface SearchContext
by
- The locating mechanism to useWebElement
s, or an empty list if nothing matches.By
,
WebDriver.Timeouts
WebElement findElement(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.
See W3C WebDriver specification for more details.
findElement
in interface SearchContext
by
- The locating mechanismNoSuchElementException
- If no matching elements are foundBy
,
WebDriver.Timeouts
boolean isDisplayed()
Point getLocation()
See W3C WebDriver specification for more details.
Dimension getSize()
See W3C WebDriver specification for more details.
Rectangle getRect()
See W3C WebDriver specification for more details.
java.lang.String getCssValue(java.lang.String propertyName)
See W3C WebDriver specification for more details.
propertyName
- the css property name of the element