Tuesday 4 September 2012

Verify the height and width of image in Selenium


You can verify image height and width with help of selenium.

I have shared sample script. In this script i'm storing width and height of image and then comparing it with expected width and height.

CODE - 

int wid = (Integer) selenium.getElementWidth("css=p > img.medialeft");
int hght = (Integer) selenium.getElementHeight("css=p > img.medialeft");
System.out.println(wid);
System.out.println(hght);
 if ((hght == 234) && (wid == 140))
    {
      
       System.out.println("image size" +wid + " X "  + hght + "pixels");
  
     }

 Else
   {
       System.out.println("Image width and height is not matching with expected");
   }



Here expected width and height is 140 and 234 respectively.
In if condition it is checking whether width and height is same as required, if it is same it will print, else will move to other part or any error message.





No comments:

Post a Comment