Example On getRect() Method

Note: You need to create a maven project and you need add Selenium 4.0.0-alpha-3 dependency.

Below script is to print the Height and width , x and y coordinates of web button.

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver; 
import io.github.bonigarcia.wdm.WebDriverManager;

public class getRectExp {
     
      public static void main(String[] args) {           
           
            WebDriverManager.chromedriver().setup();
            WebDriver driver=new ChromeDriver();
            driver.get("https://www.facebook.com/");
            driver.manage().window().maximize();
            WebElement siginObj=driver.findElement(By.xpath("//button[@name='websubmit']"));
           
            System.out.println("Sign Up button Height :: " +siginObj.getRect().height);
            System.out.println("Sign Up button width :: "+siginObj.getRect().width);
            System.out.println("Sign Up button x coordinate :: "+siginObj.getRect().x);
            System.out.println("Sign Up button y coordinate :: "+siginObj.getRect().y);
           
      }

}

Comments