Brokenlinks and images

The main difference between broken and non broken is the non broken is gives status code 200



List<WebElement>li=driver.findElements(By.tagName("a"));
li.addAll(driver.findElements(By.tagName("img")));
System.out.println(li.size());
for(WebElement k:li) {
if(!k.getText().isEmpty()) {



connection=(HttpURLConnection) new URL(k.getAttribute("href")).openConnection();
connection.connect();
int code= connection.getResponseCode();
System.out.println(k.getText()+"---------------------"+code);

}
}
connection.disconnect();

Comments

Popular posts from this blog

Selenium Locators usage

Java Theory interview questions

java programmes frequently asked in interview