Here are the difference between getSize() and getLocation() methods :
getSize() :
Note:
Makesure to import "org.openqa.selenium.Dimension;" package.
getLocation() :
Sample code to get the "x" and "y" coordinates :
Note:
Makesure to import "org.openqa.selenium.Point;" package.
getSize() :
- It will returns the "Dimension" object.
- If you want to get the width and Height of the specific element on the webpage then use "getsize()" method.
- WebDriver driver = new FirefoxDriver();
- driver.get("https://google.com");
- Dimension dimesions=driver.findElement(By.id("gbqfsa")).getSize();
- System.out.println("Width : "+dimesions.width);
- System.out.println("Height : "+dimesions.height);
Makesure to import "org.openqa.selenium.Dimension;" package.
getLocation() :
- It will return the "Point" object.
- If you want to get the exact "x" and "y" coordinates of the element then use "getLocation()" method.
Sample code to get the "x" and "y" coordinates :
- WebDriver driver = new FirefoxDriver();
- driver.get("https://google.com");
- Point point=driver.findElement(By.id("gbqfsa")).getLocation();
- System.out.println("X Position : "point.x);
- System.out.println("Y Position : "point.y);
Makesure to import "org.openqa.selenium.Point;" package.
No comments:
Post a Comment