Back

Explore Courses Blog Tutorials Interview Questions
+1 vote
1 view
in DevOps and Agile by (19.7k points)

What is the most convenient way using Selenium WebDriver to check if an URL GET returns successfully (HTTP 200)?

In this particular case, I'm most interested in verifying that no images of the current page are broken.

1 Answer

0 votes
by (62.9k points)

I would recommend you try using the code below:

List<WebElement> allImages = driver.findElements(By.tagName("img"));

for (WebElement image : allImages) {

  boolean loaded = ((JavaScriptExecutor) driver).executeScript(

      "return arguments[0].complete", image);

  if (!loaded) {

    // Your error handling here.

  }

}

If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s Selenium training

Browse Categories

...