Find broken images in page & image replace by another image

前端 未结 3 1973
说谎
说谎 2021-02-14 02:46

Hi I am using selenium webdriver 2.25.0 & faceing the some serious issues,

  1. how to find broken images in a page using Selenium Webdriver
  2. How to find th
3条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-14 02:47

    The next lines are not optimized, but they could find broken images:

    List 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
    }
    

    Regarding your second issue, I think I didn't understand it correctly. Could you explain it with more detail?

提交回复
热议问题