Reputation: 501
I want to verify the first image on my page is a certain dimension. I have the code I'm using right now to GET the dimensions, but now, I need to verify that the image is 1024 pixels wide... How do I do this?
Dimension elementDimensions=(Insert Element Here).get(0).getSize();
elementDimensions.getHeight();
elementDimensions.getWidth();
Assert.assertTrue.........
Upvotes: 2
Views: 10324
Reputation: 3927
I think you already getting width and height from driver and known what would be the expected value. So you can use Assertions here..
Generally i will use like below
driver.get("http://docs.seleniumhq.org/");
int width=driver.findElement(By.tagName("img")).getSize().getWidth();
int hight=driver.findElement(By.tagName("img")).getSize().getHeight();
System.out.println(width +">>>"+hight);
//to verify width
Assert.assertEquals(width, 200);
Thank You, Murali
Upvotes: 6