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

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

Solved 1 Answers 262 Views Programming
0 1

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

1 Answer

0
Best answer
0
 

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();
 }

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.
...