Selenium WebDriver Tutorial WebElement Methods

      No Comments on Selenium WebDriver Tutorial WebElement Methods


In this example we will discuss about the WebElement Methods available in Selenium WebDriver. Refer to the Link for WebElement API Methods.


Generally we mainly use methods like sendKeys(),click(),getText(). But they are so many other methods available to verify the input data entered by the user in the textbox. Verify the Css Attributes like color and font-size of the Web Element.

Is WebElement is a Interface or Class??

Answer:: Interface
WebElement is an interface and all the abstract methods in the interface are implemented by the RemoteWebElement Class. Refer to the Link to get more information on Inheritance and Interfaces.

How do we know the Class which are implementing the Interface??

Hold the control button in the keyboard and place the mouse on the method and select Open Implementation as shown below to get the details of the classes which are implementing the interface.

Classes implementing the interface WebElement

Classes implementing the interface WebElement


RemoteWebElement Class implementing the WebElement Interface

RemoteWebElement Class implementing the WebElement Interface

getCssValue("background-color")
Returns the Color of the WebElement

getCssValue("font-size")
Returns the font-size

getLocation()
Returns the Location of the WebElement. A point, containing the location of the top left-hand corner of the element

getAttribute("value")
Returns the input data entered by the user in the Text box using sendkeys() method.

Example for fetching the background-color and font-size of the Elements in the Web Page:

Output:

Entered Text:: total-qa
id:: username
name:: username
class:: textboxcolor padding
location:: (268, 849)
size:: (231, 30)
color:: rgb(255, 255, 0)
fontsize:: 13.3333px
Tag Name:: input

Conclusion:

In this example we have learnt how to use the WebElement Methods in Selenium WebDriver.

Leave a Reply

Your email address will not be published. Required fields are marked *