Back
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.
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. }}
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!
31k questions
32.8k answers
501 comments
693 users