Wednesday, 28 August 2013

How to store Left & Top (Location) | Width & Height of an Image/Element using Selenium Webdriver ?


Store width and height of an Image/Element:

int width = driver.findElement(By.id(Value)).getSize().getWidth();
int height = driver.findElement(By.id(Value)).getSize().getHeight();
(or)
System.out.println(driver.findElement(By.id(Value)).getSize());

Store left and top location of an Image/Element:

Point TopLeftlocation =driver.findElement(By.id(Value)).getLocation();
System.out.println(TopLeftlocation.getX() + "\t" + TopLeftlocation.getY());
(or)
Point p = driver.findElement(By.id(Value)).getLocation();
System.out.println("X position:"+p.x);
System.out.println("Y position:"+p.y);
(or)
System.out.println(driver.findElement(By.id(Value)).getLocation());

1 comment: