getLocation(), getSize(), getTagName() and getText() WebElement methods in selenium webdriver

Views: 1399   

In this tutorial i am going to explain following important methods in selenium webdriver. These methods are used to get information about a particular element

  1. getLocation() : Element is where on the page.
  2. getSize() : It Returns width and height of the element.
  3. getTagName() : It gets the tag name of the current element.
  4. getText() : It gets visible text for an element.

Example :

package com.selenium.practise;

import org.openqa.selenium.By;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class ExampleWebElementMethods {

    public static void main(String[] args) {
        System.setProperty("", "E:\\Soft Wares\\chromedriver.exe");
        WebDriver driver = new ChromeDriver();
        String Url = "";
        WebElement sigin = driver.findElement("gb_70"));
        //getLocation() WebElement method
        Point location = sigin.getLocation();
        System.out.println("Location of X :"+ location.getX()+ "," +"Location of Y :" +location.getY());
        //getSize() WebElement method
        Dimension size = sigin.getSize();
        System.out.println("Width :"+size.getWidth()+ "," +"Height : "+size.getHeight());
        //getText() WebElement method
        String text = sigin.getText();
        System.out.println("Text :" +text);
        //getTagName() WebElement method
        String tagName = sigin.getTagName();
        System.out.println("Tagname :"+tagName);
        //close the browser



Output :
Location of X :934,Location of Y :16
Width :69,Height : 30
Text :Sign in
Tagname :a

On By