Selenium Interfaces and Methods

In Selenium we have total 13 interfaces. All these interfaces has abstract and non- static methods. 

Interfaces of Selenium webdriver.
The following are the Interfaces of 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


Methods of SearchContext interface: 
1. findElement() 
2. findElements() 
Methods of WebDriver interface: 
1. close() 
2. get() 
3. getTitle() 
4. getPageSource() 
5. getCurrentUrl() 
6. getWindowHandle() 
7. getWindowHandles() 
8. manage() 
9. navigate() 
10. quit() 
11. switchTo() Methods of 

TakesScreenshot interface:
 1. getScreenshotAs(args)

Methods of JavascriptExecutor interface:
 1. executeScript()
 2. executeAsyncScript() - we don’t use this for automation

METHODS OF WebElement interface: 
1. clear()
         -It is a method present in 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 the 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 string and the return type of this method is String.

5. getLocation() 
a. getLocation() is a method present in WebElement interface. 
b. It returns an instance of Point class. 
c. 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() 

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 use to get the tag name of an element. It doesn’t accept any argument. 

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

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

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

12. isSelected()
 a. isSelected() is a method present in WebElement interface. 
 b. It checks whether an element is selected or not on the webpage.
 c. If the element is selected on the webpage, it returns true. 
 d. 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 in to a text box or a text area. It returns nothing, it is void. 

14. submit() 

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

1. getLocation():
- A method of WebElement interface which is used to get the position of an element on the
webpage.
-- It returns an instance of Point class. Point class has few methods like getX(), getY()...
-- getX() method returns the X co-ordinate of the given element in the form of int and hence,
the return type is integer.
int eleObjXcor = eleObj.getLocation().getX();
- getY() method returns the Y co-ordinate of the given element in the form of int and hence
the return type is integer.
int eleObjYcor = eleObj.getLocation().getY();


2. getSize():
- is a method of webelement interface which is used to get the dimensions of an element on
the webpage.
-- it returns an instance of Dimension class.
Dimension class has few methods like getHeight(), getWidth()..
- getHeight() method returns the height of the given element in the form of int and hence the
return type is integer.
int eleObjHeight = eleObj.getSize().getHeight();
- getWidth() method returns the width of the given element in the form of int and hence the
return type is integer.
int eleObjWidth = eleObj.getSize().getWidth();


3. isDisplayed():
- is a method of webelement interface which is used to check whether an element is
displayed or not on the webpage.
-- if the element is displayed, it returns true, and if it is not displayed, it returns false and
hence the return type is boolean.

4. isEnabled():
- is a method of webelement interface which is used to check whether an element is
ENABLED or not on the webpage.
-- if the element is enabled,it returns true, and if it is disabled, it returns false. and hence the
return type is boolean.

5. sendKeys():


6. isSelected():
- is a method of webelement interface which is used to check whether an element is Selected
or not on the webpage.
-- if the element is selected, it returns true, and if it is not selected, it returns false. and hence
the return type is boolean.

7. getAttribute(String)
- is a method of webelement interface which returns the value of the specified attribute in
the form of string.
-- > if the specified attribute name is found in the html source code of an element, it returns the
value of that particular attribute.
- In case, if the specified attribute name is not found, it returns an empty string object.
 it doesn’t throw any exception

8. getText():
- is a method of webelement interface which returns the text of an element in the form of
string and hence the return type is String. If no text is present it returns empty string.

9. getTagname():
- is a method of webelement interface which returns the tagname of an element in the
form of string and hence the return type is String

10. getCssValue():

11. getRect()
- is a method of webelement interface.
- it 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();

Post a Comment

0 Comments