Member-only story
Case Study: Broken Link Checker
How to check a website for broken links using Selenium WebDriver
5 min readSep 3, 2023
While Selenium WebDriver is mainly used for web test automation, don’t forget Selenium is an automation framework, which can be used for other automation tasks, not limited in testing. In this case study, I will show a simple way to scrape a website’s links and check if they are broken, using Selenium WebDriver with C#.
This article will take this a tiny step further and specifically check for broken links with a little bit of programming know-how.
Note: This will be a simple unoptimised script just for demonstration purposes.
Test Design
- Create a list of URLs to check (
to_check_list
), starting with a site’s home URL. - Retrieve one URL from the
to_check_list
- Check whether that URL is broken.
- If it is a valid URL, visit the URL using Selenium WebDriver
- Get a list of hyperlinks from the new page, and add them to the
to_check_list
(unless it is already there) - Repeat Steps 2–5, until all URLs in the
to_check_list
have been checked. - Print out all the broken links.