2
我需要自动化(使用硒)的网页上丢失的图像。现在的图像可以以三种方式被加载: 1)寻找缺少图片硒
<img src="http://something.com/google.png">
2)
<img src="/path/to/file/image.jpg">
3)
<div class="someIcon" autoID="some-icon"></div>
上述信息可以来自CSS(例如
.someIcon {
height: 97px;
width: 93px;
background-image: url("../assets/images/some_icon.png");
background-size: 93px 97px;
}
现在有了这些在html页面上加载图像的不同方式,我如何编写自动化来识别图像是否丢失?
问题1)能够使用可以解决
List<WebElement> imagesList = _driver.findElements(By.tagName("img"));
for (WebElement image : imagesList)
{
HttpResponse response = new DefaultHttpClient().execute(new HttpGet(image.getAttribute("src");));
if (response.getStatusLine().getStatusCode() != 200)
// Do whatever you want with broken images
}
如何约2)& 3)?
感谢, MATEEN
你是正确的第二种情况SRC的价值将被解析为完整的URL。谢谢 – 2014-09-29 22:53:42