How to verify dimensions of image in Selenium Java Webdriver?

一曲冷凌霜 提交于 2021-01-27 17:45:58

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!