How To Find Broken Links In Selenium?

How To Find Broken Links In Selenium?

broken links in selenium

How To Find Broken Links In Selenium?

How To Find Broken Links In Selenium?

How To Find Broken Links In Selenium?


How To Find Broken Links In Selenium?

How To Find Broken Links In Selenium 

Nothing’s more frustrating than coming across broken links while navigating through a website, right? But fear not, for we’re here to help you understand why these links break, what are broken links in selenium and how to track them down using Selenium?

Let’s First Understand What are Broken Links?

Enroll now and take the first step towards a successful career. Click here to join our courses today!

What are Broken Links?

When hyperlinks on a website no longer lead to their desired destination or target page, they are called broken links or dead links. These links are considered “broken” because the URL they refer to has either changed or the linked page has been deleted & removed. A “404 error” page appears when a user clicks on a broken link.

Imagine clicking links on a website and getting error messages. It’s really unimpressive, right?

Not only does having too many broken links make it harder for people to use your product, but it also hurts its trustworthiness. People may not trust your product or service if they think your website is not well taken care of and is not interesting.

In addition to the user experience and credibility, broken links can also harm your product’s search engine rankings. When search engines like Google crawl through your website and find many 404 errors (page not found), they see it as a sign of poor quality or outdated content.. 

Thus, your website’s search engine ranking may drop, making it difficult for potential visitors to find it.

So, keeping an eye out for broken links & fixing them quickly is a valuable practice to ensure your web product remains reliable, user-friendly, and performs well both for your visitors and search engines too.

Why Do Software Testers Use Selenium To Find Broken Links?

Web automation testing mainly relies on Selenium tool, a powerful & most popular web automation technology that helps users interact with web sites, perform operations, and extract data.

However, even with the convenience it provides, broken links can cause frustration for both users and website owners. These broken links can lead to errors, missing pages, malfunctioning features, and an overall poor user experience. Therefore, it becomes important to promptly identify and replace broken links on a website.

Level up your skills in Software testing. Enroll now and become an expert. 

Selenium finds broken links for software testers for numerous reasons:

1) Automation Efficiency: Selenium tool allows testers to automate the process of checking for broken links, saving time & effort compared to manual testing. It can handle large-scale link checking in a more efficient manner.

2) Comprehensive Testing: Selenium can navigate through web pages and interact with various elements, providing a comprehensive testing approach. Testers can identify broken links in different scenarios and user interactions.

3) Cross-Browser Compatibility: Selenium supports multiple web browsers, helps testers to check for broken links across different browsers and ensure consistent functionality.

4) Integration with Test Frameworks: Selenium smoothly integrates with various testing frameworks, enabling testers to include broken link checks as part of their existing test suites.

5) Reusability and Scalability: Once automated, the link checking scripts can be reused for regression testing or testing on similar websites, making it scalable for future projects.

6) Early Bug Detection: Identifying broken links early in the development cycle allows developers to address issues promptly, leading to a more stable and reliable website.

7) Consistent and Reliable Results: Selenium’s automated approach ensures consistent and reliable results, reducing the chances of human errors in manual link checking.

Also Read : What Is Software Testing

How To Find Broken Links In Selenium?

Finding broken links in Selenium involves the following steps:

Step 1: Setup Selenium and import libraries

Ensure you have Python installed on your system and install Selenium using the following command:

For Example:

Then, import the necessary libraries:

For Example:

Step 2: Launch the web browser

Select the browser you prefer (like Chrome) and provide the path to the appropriate WebDriver. Download the WebDriver for your browser version from the official website.

For Example:

Step 3: Navigate to the website

Enter the website URL to detect broken links.

Step 4: Find and check links

Locate all the links on the web page and verify if they are working or broken by sending HTTP requests and checking the status codes.

Step 5: Close the browser

After testing, close the browser.

That’s it! With this simple Selenium script, you can identify and print the broken links on the specified website. You can modify the script as needed, such as writing the broken links to a file or performing additional actions upon finding them.

Note: To handle exceptions and network-related errors to ensure the script runs smoothly and provides accurate results.

HTTP Status Codes for Broken Links

Below is a table listing some common HTTP status codes that indicate broken links:


HTTP Status CodeDescription
404Not Found – The requested web page is not available on the server. This is the most common status code for broken links.
400Bad Request – The server cannot understand the request due to malformed syntax or invalid request message framing.
403Forbidden – The server understands the request, but the user doesn’t have access to the resource.
410Gone – The requested resource is no longer available on the server, & there is no forwarding address.
500Internal Server Error – The server couldn’t fulfill the request due to an unexpected circumstance.
502Bad Gateway – The server, while acting as a gateway or proxy, received an invalid response from the upstream server.
503Service Unavailable – The server is currently unable to handle the request due to temporary overloading or maintenance.

What Are The Common Reasons For Broken Links

Website broken links have numerous causes:

1) Page Removal/Renaming: Links to a page that is removed or renamed without updating its links will break.

2) Incorrect URL Typing: Human error while typing URLs in the website’s content or code can lead to broken links.

3) Linking to External Websites: When a website links to external pages, those pages may change their URLs or get deleted, resulting in broken links.

4) Expired Content: If a website has time-sensitive content, such as events or promotions, links to expired pages can become broken when the content is no longer available.

5) Broken Redirects: Incorrect or broken redirection rules can lead to broken links when users are redirected to non-existent pages.

6) Website Migration or Redesign: During website migrations or redesigns, internal link structures may change, leading to broken links if not handled correctly.

7) Image and Media Sources: Broken links can also occur when images or media files are moved or deleted without updating the links.

8) HTTP to HTTPS Transition: If a website transitions from HTTP to HTTPS but internal links are not updated accordingly, they may become broken.

9) Server Issues: Temporary server issues or downtime can result in broken links when users try to access the website during that time.

10) Expiring or Changing Domain: If a website’s domain name expires or is changed, links pointing to the old domain may become broken.

11) Link Shorteners: The use of link shorteners may lead to broken links if the shortening service is discontinued or if the short URL is incorrectly formatted.


  • Website creation and testing require regular checks for broken links to ensure a smooth user experience.
  • Selenium WebDriver and programming languages like Java, Python, C#, or PHP enables efficient broken link testing without any third-party tools.
  • Selenium provides HTTP Status Codes to identify and address broken links effectively.

If you found this post on “broken links in selenium” helpful, please share it. Your support can benefit more people in learning about this useful technique.

Ready to become a Software Tester?

Enroll now at Technogeeks to secure your future!

Get Free Career Counseling +91 8600998107 Or +91 7028710777 


What is a 404 error and broken links?

A 404 error means that a web page or resource couldn’t be found, often because of a broken link.

How can I check broken links In Selenium?

You can use Selenium’s WebDriver to navigate web pages and check for broken links by looking at the HTTP response codes.



Leave a Reply

Your email address will not be published. Required fields are marked *

Blogs You May Like

Get in touch to claim Best Available Discounts.

If You Are Looking for Job Assistance Please Fill Up the Form.

× How can I help you?