Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
472 views
in Programming by

Requires code in java that will catch all anchor tags from page, store them & check broken or not

1 Answer

0 like 0 dislike
by The go-to Tester (181 points)
selected by
 
Best answer
 

First you can find appropriate link. Identify an element and get attribute href.

Then:

We can use HttpURLConnection Class and getResponseCode method for finding the reponse code of the URL.

public static int getResponseCode(String urlString) throws MalformedURLException, IOException {
     URL u = new URL(urlString);
     HttpURLConnection huc =  (HttpURLConnection)  u.openConnection();
     huc.setRequestMethod("GET");
     huc.connect();
     return huc.getResponseCode();
 }

...