How To Find Broken Links Using Selenium WebDriver

Find Broken Links Using Selenium WebDriver:

One of the key test case is to find broken links on a webpage. Due to existence of broken links, your website reputation gets damaged and there will be a negative impact on your business. It’s mandatory to find and fix all the broken links before release. If a link is not working, we face a message as 404 Page Not Found.

Let’s see some of the HTTP status codes.

200 – Valid Link
404 – Link not found
400 – Bad request
401 – Unauthorized
500 – Internal Error
Consider a test case to test all the links in the home page of “”

Below code fetches all the links of a given website (i.e., using WebDriver commands and reads the status of each href link with the help of HttpURLConnection class.

Click here for more information on HttpURLConnection

Given clear explanation in the comments section with in the program itself. Please go through it to understand the flow.

If this post on “Finding Broken Links Using Selenium WebDriver” was able to help, then don’t mind sharing it with others.

If you are not regular reader of then I highly recommend you to signup for the free email newsletter using the below link.

Rajkumar SM is a founder of SoftwareTestingMaterial. He is a certified Software Test Engineer by profession and blogger & youtuber by choice. He has an extensive experience in the field of Software Testing. He writes here about Software Testing which includes both Manual and Automation Testing. He loves to be with his wife and cute little kid 'Freedom'.

2 thoughts on “How To Find Broken Links Using Selenium WebDriver”

  1. i want to same with testng please help

    • Hi Pravash, convert the class in to TestNG class. Try and let me know, if you need any help.

Leave a Comment

Share via
Copy link
Powered by Social Snap