Home » selenium-tutorial » Commands for WebElements

Newly Updated Posts

Commands for WebElements

When we talk about WebElements, we talk about source code or HTML documentation of a Web page. Web Elements in the user interface are the elements that are due to the HTML tag or syntax that are written in Dom structure.These tags have starting and ending tag.

So to interact with these webElements, first we need to take webElements as a return type from any of webdriver method. Take the return type from the findElements method as below:

WebElement driver= driver.findElement(By.name(“Email”));

1) click: This method is used to click to the element in web page and returns void(no return type).Command for click is below:

WebElement driver1= driver.findElement(By.name(“XXXXX”));
driver1.click();

2) clear: This method clears the value from the web element for ex: any text present in the text field gets cleared after evoke clear method. Command for clear is displayed below.

WebElement driver1= driver.findElement(By.name(“Email”));
driver1.clear();

3) getAttribute: This method gives the value of the attribute name passed as a parameter and return a string. Command for clear is displayed below.

WebElement driver1= driver.findElement(By.name(“Email”));
driver1.getAttribute(“name”); //This will return Email as a string

4) getCssValue: This method will return the string and provide the value of the css attribute value.

WebElement driver1= driver.findElement(By.name(“Email”));
driver1.getCssValue(“background-border”);

5) getSize: This method will give you the size of the element and return you the Dimension object.

WebElement driver1= driver.findElement(By.name(“Email”));
driver1.getSize();

6) getLocation: This method do not required any parameter and provided the x and y co-ordinated and return the object of Point.

WebElement driver1= driver.findElement(By.name(“Email”));
Point coOrdinates =driver1.getLocation();
coOrdinates.x;
coOrdinates.y;

7) getText: This method provide the text of the element and return the object as String.

WebElement driver1= driver.findElement(By.name(“Email”));
String coOrdinates =driver1.getText();

8) Submit: This method submits the the web page for its a form type image its works same as click.

WebElement driver1= driver.findElement(By.name(“Email”));
driver1.submit();

9) isDisplayed: This method helps in getting the presence of web element on web page.This method do not accept any parameter and returns a Boolean.

WebElement driver1= driver.findElement(By.name(“Email”));
driver1.isDisplayed();

10) isEnabled: This method helps to know whether the element is Enabled or not and return Boolean as an Object.

WebElement driver1= driver.findElement(By.name(“Email”));
driver1.isEnabled();

11) isSelected: This method helps to know whether the element in web page is selected or not . For example a check box is checked or not and return Boolean as Object.

WebElement driver1= driver.findElement(By.name(“Email”));
driver1.isSelected();