问题
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.........
回答1:
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
来源:https://stackoverflow.com/questions/37071128/how-to-verify-dimensions-of-image-in-selenium-java-webdriver