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