Methods in WebElement Interface

Methods in WebElement Interface



In this article, we will learn about the various interface present in the Selenium and will look into the details about the various methods present in the WebElement Interface.

First, let's look into the various interface present in the selenium.
In SELENIUM we have a total of 13 interfaces. All these interfaces have abstract and non-static methods. The following are the interfaces of the 
SELENIUM webdriver

1. SearchContext 
2. WebDriver 
3. TakesScreenshot 
4. JavascriptExecutor 
5. Navigation 
6. OutputType 
7. WebElement 
8. TargetLocator 
9. Alert 
10. Action 
11. ExpectedConditions 
12. Options 
13. Timeouts 




Now let's look into the details about the various methods present in the WebElement Interface. 

1. Clear()

·         It is a method present in the WebElement interface. 
·         It is used to clear any value which is present in any element (e.g. text box, text area, etc). It returns nothing, it is void. 

2. click() 

A method of WebElement interface which is used to click on any element. It doesn’t return anything, it is void. 

3. getAttribute() 

·         It is used to get the value of the attribute in the form of string. 
·         As an argument to this method, we pass the attribute name in the form of string.    

    ·       When we pass an attribute name which is not present in the HTML source code of an element as an argument to this method, it returns an empty string (“ ”). 
  

4. getCssValue() 

A method of WebElement interface. It returns the value of the specified style-related attribute in the form of a string and the return type of this method is String. 



5. getLocation() 

·         getLocation() is a method present in WebElement interface. 
·         It returns an instance of Point class. 
·         Point class has few non-static methods like getX() and getY()

1. getX() method returns the coordinate of an element. 
2. getY() method returns the y coordinate of an element. 

6. getRect() 

·         It is a method of webelement interface which is used to get the x and y coordinates of elements and also to find the height and width of an element.
·         it has few methods like getPoint() and getDimension(). 
·         getPoint() method returns the instance of Point class. int eleXcor = eleObj.getRect().getPoint().getX(); 
·         getDimension() method returns the instance of Dimension class. int eleXcor = eleObj.getRect().getDimension().getWidth();

7. getSize() 

·         getSize() is a method present in WebElement interface. 
·         It returns an instance of Dimension class. 
·         Dimension class has few non static methods     like getHeight() and getWidth()

a. getHeight() method returns the height of an element. 
b. getWidth() method returns the width of an element. 

8. getTagName() 

It is used to get the tag name of an element. It doesn’t accept any argument. 

9. getText() 

·         It is used to get the text present in an element. It doesn’t accept any argument. 
·         When there is no text present in the HTML source code of an element and we are using the getText() method to retrieve the text of an element, it returns an empty string. 



10. isDisplayed() 

·         isDisplayed() is a method present in the WebElement interface. 
·         It checks whether an element is present or not on the webpage. 
·         If the element is present on the webpage, it returns true and if the element is not present on the webpage, it returns false. 


11. isEnabled() 

·         isEnabled() is a method present in WebElement interface. 
·         It checks whether an element is enabled or not on the webpage.
·         If the element is enabled on the webpage, it returns true and if the element is disabled on the webpage, it returns false. 

12. isSelected() 

·         isSelected() is a method present in WebElement interface. 
·         It checks whether an element is selected or not on the webpage. 
·         If the element is selected on the webpage, it returns true and if the element is not selected on the webpage, it returns false. 

13. sendKeys()

A method of WebElement interface which is used to enter a value into a text box or a text area. It returns nothing, it is void. 

14. submit() 

We can use the submit method to click on an element if the element is present inside a form(tag) and the HTML source code of the element has an attribute called type = “submit”. When both the conditions satisfied we use the submit() method. 
e.g. 
<form>
<input type="submit"> 
</form>








SHARE THIS

Author:

My Name is Ankur Jain and I am currently working as Automation Test Architect.I am ISTQB Certified Test Manager,Certified UI Path RPA Developer as well as Certified Scrum Master with total 12 years of working experience with lot of big banking clients around the globe.I love to Design Automation Testing Frameworks with Selenium,Appium,Protractor,Cucumber,Rest-Assured, Katalon Studio and currently exploring lot in Dev-OPS as well. I am currently staying in Mumbai, Maharashtra. Please Connect with me through Contact Us page of this website.

Previous Post
Next Post