Hi I am using selenium webdriver 2.25.0 & faceing the some serious issues,
Thanks in advance for your value-able suggestions.
What are Broken Image Links? A broken image is nothing more than a link that transfers users to a 404 error or an underloaded image icon. Underloaded images and 404 pages are not only unattractive. They provoke rejection and degrade conversion.
The easiest way to detect broken images on your WordPress website is using a plugin. One of such plugins is the Broken Link Checker. With this plugin, you can scan your site's internal and external links for any broken links and images.
The accepted answer requires that you use a proxy with an extra call to each image to determine if the images are broken or not.
Fortunately, there is another way you can do this using only javascript (I'm using Ruby, but you can use the same code in any executeScript
method across the WebDriver bindings):
images = @driver.find_elements(:tag_name => "img")
broken_images = images.reject do |image|
@driver.execute_script("return arguments[0].complete && typeof arguments[0].naturalWidth != \"undefined\" && arguments[0].naturalWidth > 0", image)
end
# broken_images now has an array of any images on the page with broken links
# and we want to ensure that it doesn't have any items
assert broken_images.empty?
To your other question, I would recommend just taking a screenshot of the page and having a human manually verify the resulting screenshot has the correct images. Computers can do the automation work, but humans do have to check and verify its results from time to time :)
The next lines are not optimized, but they could find broken images:
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
}
Regarding your second issue, I think I didn't understand it correctly. Could you explain it with more detail?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With