You are on page 1of 2

WebElements Commands

WebElement and the List of Actions can be performed on various WebElements.

Commands Description Syntax Accepts Parameter Returns

If this element is a text entry


Clear() driver.findElement(By.id("UserName")).clear(); Accepts Nothing as a parameter Returns Nothing.
element, this will clear the value.

This simulates the clicking of any


Click() driver.findElement(By.id("UserName")).click(); Accepts Nothing as a parameter Returns Nothing.
element.

This method works well/better


than the click () if the current
Submit() driver.findElement(By.id("UserName")).submit(); Accepts Nothing as a parameter Returns Nothing.
element is a form, or an element
within a form

This simulates typing into an driver.findElement(By.id("UserName")).sendkeys Accepts CharSequence as a


Sendkeys() Returns Nothing.
element, which may set its value ("T-shirts"); parameter

Element Visibility Methods

This method determines if an


boolean status = driver.findElement(By.id Returns a boolean value
IsDisplayed element is currently being Accepts nothing as a parameter
("UserName")).isDisplayed(); (true/false).
displayed or not.

This determines if the element boolean status = driver.findElement(By.id Returns boolean value
IsEnabled Accepts nothing as a parameter
currently is Enabled or not ("UserName")).isEnabled; (true/false).

Determine whether or not this


element is selected or notThis
operation only applies to input
elements such as Checkboxes, boolean status = driver.findElement(By.id("Sex- Returns boolean value
IsSelected Accepts nothing as a parameter
Select Options, and Radio Male")).isSelected(); (true/false).
Buttons. This returns True if the
element is currently selected or
checked, false otherwise.
This method will fetch the visible
(i.e. not hidden by CSS) innerText
of the element.This returns an
getText() String linkText = element.getText(); Accepts nothing as a parameter Returns a String value.
innerText of the element, including
sub-elements, without any leading
or trailing whitespace.

This method gets the tag name of


this element.This does not return
String tagName = driver.findElement(By.id
getTagName() the value of the name attribute but Accepts nothing as a parameter Returns a String value.
("SubmitButton")).getTagName();
return the tag for e.g. “input“ for
the element <input name="foo"/>.

This method Fetch CSS property


getCssValue() driver.getCssValue(); Accepts nothing as a parameter Returns a String value.
value of the give element.

This method gets the value of the Accepts the String as a


getAttribute() String attValue = driver.getAttribute("id"); Returns a String value.
given attribute of the element. parameter

This method fetch the width and Returns the Dimension


getSize() Dimension dimensions = element.getSize(); Accepts nothing as a parameter
height of the rendered element. object.

This method locate the location of


getLocation() Point point = element.getLocation(); Accepts nothing as a parameter Returns the Point object.
the element on the page

You might also like