How to convert xpath location to pixel
2 answers
Find the element and use getLocation()
method :
WebElement element = driver.findElement(By.id("my_id"));
System.out.println(element.getLocation());
Note that it getLocation()
returns "Point" (the coordinates of the top-left corner of the element).
+2
source to share
Below is the complete program.
public void getCoordinates(){
driver = new ChromeDriver();
driver.get("https://www.google.com");
WebElement element = driver.findElement(By.id("hplogo"));
Point location = element.getLocation();
int x = location.getX();
int y = location.getY();
System.out.println("Coordinates of an element is : " + x + " and " + y);
}
+2
source to share