Join 500+ Software Testing professionals. Solve problem and get your problem solved. Register Now!

How can I check broken links on webpage using Selenium Webdriver java

Solved 1 Answers 269 Views Programming
0 1

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

1 Answer

Best answer

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


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();
     return huc.getResponseCode();

answered by (151 points)
selected by

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.