如何在 Selenium Java Webdriver 中验证图像的尺寸? [英] How to verify dimensions of image in Selenium Java Webdriver?

查看:30
本文介绍了如何在 Selenium Java Webdriver 中验证图像的尺寸?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想验证我页面上的第一张图片是特定尺寸的.我有我现在用来获取尺寸的代码,但是现在,我需要验证图像的宽度是否为 1024 像素...我该怎么做?

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.........

推荐答案

我认为您已经从驱动程序中获得了宽度和高度,并且知道期望值是多少.所以你可以在这里使用断言..

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);

谢谢,壁画

这篇关于如何在 Selenium Java Webdriver 中验证图像的尺寸?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆