{"id":16534,"date":"2024-06-10T09:15:49","date_gmt":"2024-06-10T03:45:49","guid":{"rendered":"https:\/\/www.h2kinfosys.com\/blog\/?p=16534"},"modified":"2025-12-08T03:52:19","modified_gmt":"2025-12-08T08:52:19","slug":"broken-links-in-selenium","status":"publish","type":"post","link":"https:\/\/www.h2kinfosys.com\/blog\/broken-links-in-selenium\/","title":{"rendered":"Broken links in Selenium"},"content":{"rendered":"\n<p>A broken link disrupts the user journey, blocks conversions, reduces trust, and lowers search engine rankings. Companies lose <strong>up to 20% of customer trust<\/strong> when users land on dead pages, according to recent UX studies. QA teams must detect these issues before release.<\/p>\n\n\n\n<p>This is where Selenium testing helps teams quickly scan websites, identify broken URLs, and maintain a smooth navigation experience. If you are taking a <a href=\"https:\/\/www.h2kinfosys.com\/courses\/selenium-automation-testing-certification-course\/\" data-type=\"link\" data-id=\"https:\/\/www.h2kinfosys.com\/courses\/selenium-automation-testing-certification-course\/\">Selenium certification course<\/a> or learning through a Selenium course online, mastering broken-link detection becomes an important job skill because almost every modern web application has hundreds of links.<\/p>\n\n\n\n<p>This blog explains everything about Broken links, how to find them with Selenium, why companies take them seriously, and how you can implement step-by-step automation to detect them.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What Are Broken Links?<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"800\" height=\"400\" src=\"https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2024\/06\/what-is-a-broken-link-how-to-fix-it-on-your-website-1.png\" alt=\"Broken Links\" class=\"wp-image-32598\" title=\"\" srcset=\"https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2024\/06\/what-is-a-broken-link-how-to-fix-it-on-your-website-1.png 800w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2024\/06\/what-is-a-broken-link-how-to-fix-it-on-your-website-1-300x150.png 300w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2024\/06\/what-is-a-broken-link-how-to-fix-it-on-your-website-1-768x384.png 768w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2024\/06\/what-is-a-broken-link-how-to-fix-it-on-your-website-1-150x75.png 150w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/figure>\n\n\n\n<p>A <strong>broken link<\/strong> is a hyperlink that no longer leads to the correct destination. The link may show a 404 page, a timeout error, or redirect users to an unexpected location. It is happen for many reasons:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The target page was deleted<\/li>\n\n\n\n<li>The URL was updated without proper redirection<\/li>\n\n\n\n<li>There is a typo in the link<\/li>\n\n\n\n<li>The server is down<\/li>\n\n\n\n<li>The domain expired<\/li>\n\n\n\n<li>Network issues disrupted the request<\/li>\n<\/ul>\n\n\n\n<p>No matter the cause, a broken link affects both users and search engines.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Why Broken Links Matter in Selenium Testing<\/strong><\/h2>\n\n\n\n<p>Many testers ignore these links because they seem too basic. But companies treat them as <strong>high-impact usability defects<\/strong>. Here\u2019s why:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Broken Links Hurt User Experience<\/strong><\/h3>\n\n\n\n<p>Users expect smooth, predictable navigation. When a link fails, users leave the site.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Broken Links Damage SEO<\/strong><\/h3>\n\n\n\n<p>Search engines see this as a sign of poor maintenance. Multiple links can lower rankings.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Broken Links Reduce Conversion Rates<\/strong><\/h3>\n\n\n\n<p>If product pages, sign-up pages, or payment links break, companies lose revenue.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Broken Links Hurt Website Credibility<\/strong><\/h3>\n\n\n\n<p>Users trust brands that maintain professional websites.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Broken Links Slow Down Release Cycles<\/strong><\/h3>\n\n\n\n<p>Manual link checking takes hours. Selenium automation speeds up validation.<\/p>\n\n\n\n<p>This is why QA teams use Selenium to automate broken-link detection across large websites with thousands of URLs.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How Selenium Helps Detect Broken Links<\/strong><\/h2>\n\n\n\n<p>Selenium WebDriver does not detect this directly. It helps testers extract all links from the webpage. Then testers use Java, Python, or another language to send HTTP requests and verify the response code.<\/p>\n\n\n\n<p>The automation logic follows a simple structure:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Open the web page<\/li>\n\n\n\n<li>Collect all <code>&lt;a&gt;<\/code> tags<\/li>\n\n\n\n<li>Extract the <code>href<\/code> attribute<\/li>\n\n\n\n<li>Send an HTTP request<\/li>\n\n\n\n<li>Check the response code<\/li>\n\n\n\n<li>Report URLs with errors<\/li>\n<\/ol>\n\n\n\n<p>A link is broken if the server returns:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>404 \u2013 Not Found<\/li>\n\n\n\n<li>400 \u2013 Bad Request<\/li>\n\n\n\n<li>500 \u2013 Internal Server Error<\/li>\n\n\n\n<li>403 \u2013 Forbidden<\/li>\n\n\n\n<li>408 \u2013 Request Timeout<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Types of Broken Links Testers Commonly Find<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Internal Broken Links<\/strong><\/h3>\n\n\n\n<p>Links that break within the same domain.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">Example:<br><code>https:\/\/site.com\/products\/shoes<\/code> \u2192 returns 404.<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>External Broken Links<\/strong><\/h3>\n\n\n\n<p>Links to third-party pages that fail due to server issues, outdated URLs, or expired resources.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Redirection Issues<\/strong><\/h3>\n\n\n\n<p>Links redirect multiple times or redirect to incorrect pages.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Soft 404 Errors<\/strong><\/h3>\n\n\n\n<p>A page loads normally but displays \u201cPage Not Found.\u201d Search engines detect it as broken.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Broken Image Links<\/strong><\/h3>\n\n\n\n<p>Image URLs fail to load. Selenium can detect them using similar logic.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to Find Broken Links Using Selenium (Step-By-Step Guide)<\/strong><\/h2>\n\n\n\n<p>Below is a clear and simple step-by-step tutorial that you can practice in your Selenium certification course or Selenium course online.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 1: Set Up Your Selenium Project (Java Example)<\/strong><\/h3>\n\n\n\n<p>Install:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Java<\/li>\n\n\n\n<li>Maven<\/li>\n\n\n\n<li><a href=\"https:\/\/en.wikipedia.org\/wiki\/TestNG\" data-type=\"link\" data-id=\"https:\/\/en.wikipedia.org\/wiki\/TestNG\" rel=\"nofollow noopener\" target=\"_blank\">TestNG<\/a> (optional)<\/li>\n\n\n\n<li>Selenium WebDriver<\/li>\n\n\n\n<li>An IDE like IntelliJ or Eclipse<\/li>\n<\/ul>\n\n\n\n<p>Add Selenium and Apache HttpClient dependencies in your <code>pom.xml<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;dependency&gt;\n    &lt;groupId&gt;org.seleniumhq.selenium&lt;\/groupId&gt;\n    &lt;artifactId&gt;selenium-java&lt;\/artifactId&gt;\n    &lt;version&gt;4.14.0&lt;\/version&gt;\n&lt;\/dependency&gt;\n\n&lt;dependency&gt;\n    &lt;groupId&gt;org.apache.httpcomponents&lt;\/groupId&gt;\n    &lt;artifactId&gt;httpclient&lt;\/artifactId&gt;\n    &lt;version&gt;4.5.13&lt;\/version&gt;\n&lt;\/dependency&gt;\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 2: Write Code to Fetch All Links<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">List&lt;WebElement&gt; links = driver.findElements(By.tagName(\"a\"));\nSystem.out.println(\"Total links: \" + links.size());\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 3: Extract Link URLs<\/strong><\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">for (WebElement link : links) {\n    String url = link.getAttribute(\"href\");\n    System.out.println(url);\n}\n<\/pre>\n\n\n\n<p>Ignore null or empty URLs to avoid false reports.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Step 4: Validate Each URL<\/strong><\/h3>\n\n\n\n<p>Send an HTTP GET request and check the status code:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">public static void verifyLink(String url) {\n    try {\n        HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();\n        connection.setRequestMethod(\"GET\");\n        connection.connect();\n\n        int responseCode = connection.getResponseCode();\n\n        if (responseCode &gt;= 400) {\n            System.out.println(url + \" - Broken link\");\n        } else {\n            System.out.println(url + \" - Valid link\");\n        }\n    } catch (Exception e) {\n        System.out.println(url + \" - Invalid link\");\n    }\n}\n<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Step 5: Run the Entire Script<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">for (WebElement link : links) {\n    String url = link.getAttribute(\"href\");\n    if (url != null &amp;&amp; !url.isEmpty()) {\n        verifyLink(url);\n    }\n}\n<\/pre>\n\n\n\n<p>This script scans every link on the page and reports broken URLs.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Real-World Example: Detecting Broken Product Links<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2024\/06\/02_the_broken_link_journey-1024x768.webp\" alt=\"Broken Links\" class=\"wp-image-32599\" title=\"\" srcset=\"https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2024\/06\/02_the_broken_link_journey-1024x768.webp 1024w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2024\/06\/02_the_broken_link_journey-300x225.webp 300w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2024\/06\/02_the_broken_link_journey-768x576.webp 768w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2024\/06\/02_the_broken_link_journey-1536x1152.webp 1536w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2024\/06\/02_the_broken_link_journey-150x113.webp 150w, https:\/\/www.h2kinfosys.com\/blog\/wp-content\/uploads\/2024\/06\/02_the_broken_link_journey.webp 1600w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Imagine an ecommerce site with 3,000 product pages. A tester must ensure:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>All product categories open<\/li>\n\n\n\n<li>Every product page loads<\/li>\n\n\n\n<li>All images display<\/li>\n\n\n\n<li>All checkout links work<\/li>\n<\/ul>\n\n\n\n<p>Without automation, checking these links manually would take days. Selenium can do it in minutes.<\/p>\n\n\n\n<p>Many companies use this to ensure:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>No broken pages during flash sales<\/li>\n\n\n\n<li>No 404 errors after website redesigns<\/li>\n\n\n\n<li>No broken images during migrations<\/li>\n\n\n\n<li>No dead links that reduce customer trust<\/li>\n<\/ul>\n\n\n\n<p>Top companies depend on testers trained in Selenium to solve these issues. This is why training programs like a Selenium certification course emphasize broken-link automation.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Advanced Ways to Detect Broken Links in Selenium<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Multi-Threading for Faster Execution<\/strong><\/h3>\n\n\n\n<p>You can execute link checks in parallel using <a href=\"https:\/\/www.h2kinfosys.com\/blog\/complete-guide-to-java-ui-frameworks\/\" data-type=\"link\" data-id=\"https:\/\/www.h2kinfosys.com\/blog\/complete-guide-to-java-ui-frameworks\/\">Java<\/a> Executors.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Filtering Only Active Links<\/strong><\/h3>\n\n\n\n<p>Skip:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>mailto links<\/li>\n\n\n\n<li>javascript:void(0)<\/li>\n\n\n\n<li>telephone links<\/li>\n\n\n\n<li>anchor links (#section)<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Headless Browsers<\/strong><\/h3>\n\n\n\n<p>Use Chrome Headless for faster scanning.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Detecting Broken Images<\/strong><\/h3>\n\n\n\n<p>Replace <code>&lt;a&gt;<\/code> with <code>&lt;img&gt;<\/code> tags and validate the <code>src<\/code> attribute.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Generating HTML Reports<\/strong><\/h3>\n\n\n\n<p>Use Extent Reports or Allure to generate detailed summaries of valid and invalid links.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Common Mistakes Testers Make While Checking Broken Links<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Not Handling Redirects<\/strong><\/h3>\n\n\n\n<p>Some links return 301\/302, but they are valid.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Not Checking HTTPS Issues<\/strong><\/h3>\n\n\n\n<p>SSL certificate errors may block pages.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Not Validating External URLs<\/strong><\/h3>\n\n\n\n<p>External links matter for user trust.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Ignoring Null Links<\/strong><\/h3>\n\n\n\n<p>Empty hrefs skew results.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Scanning Pages Too Frequently<\/strong><\/h3>\n\n\n\n<p>Frequent scans may overload the server.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Broken Links and Their Impact on SEO<\/strong><\/h2>\n\n\n\n<p>Google and other search engines penalize websites with it. Here\u2019s why:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Crawlers cannot index the site correctly<\/li>\n\n\n\n<li>This links increase bounce rate<\/li>\n\n\n\n<li>The signal poor maintenance<\/li>\n\n\n\n<li>They limit backlink value<\/li>\n<\/ul>\n\n\n\n<p>Many SEO teams now ask QA teams to add automated broken-link checks to the regression suite.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Case Study: How Automation Saved a Retail Brand<\/strong><\/h2>\n\n\n\n<p>A large retail company noticed a drop in sales during a seasonal sale. After running Selenium scripts, the QA team found:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>71 internal links<\/li>\n\n\n\n<li>32 broken product images<\/li>\n\n\n\n<li>18 broken payment links<\/li>\n<\/ul>\n\n\n\n<p>Fixing these errors restored conversion rates by <strong>12%<\/strong> in the next two days. Automation provided the fastest fix.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Broken Links Monitoring: What Companies Expect from Testers<\/strong><\/h2>\n\n\n\n<p>Companies want testers who can:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Scan thousands of URLs quickly<\/li>\n\n\n\n<li>Create reusable frameworks<\/li>\n\n\n\n<li>Provide clear reports<\/li>\n\n\n\n<li>Maintain scripts with CI\/CD integration<\/li>\n\n\n\n<li>Ensure good user experience<\/li>\n<\/ul>\n\n\n\n<p>This is why many learners join a <strong>Selenium certification course<\/strong> or choose a <strong>Selenium course online<\/strong> to gain automation skills.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Best Practices for Broken-Link Automation<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Always use a stable network<\/li>\n\n\n\n<li>Use headless mode for large scans<\/li>\n\n\n\n<li>Validate both images and hyperlinks<\/li>\n\n\n\n<li>Use API calls for performance<\/li>\n\n\n\n<li>Add retry logic for flaky links<\/li>\n\n\n\n<li>Schedule daily runs through Jenkins<\/li>\n\n\n\n<li>Maintain a dashboard for reports<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Key Takeaways<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Selenium helps testers scan thousands of links automatically.<\/li>\n\n\n\n<li>Companies treat broken-link detection as a core QA responsibility.<\/li>\n\n\n\n<li>Testers must know how to extract URLs, send HTTP requests, and report failures.<\/li>\n\n\n\n<li>Training through a Selenium certification course or a <a href=\"https:\/\/www.h2kinfosys.com\/courses\/selenium-automation-testing-certification-course\/\" data-type=\"link\" data-id=\"https:\/\/www.h2kinfosys.com\/courses\/selenium-automation-testing-certification-course\/\">Selenium course online <\/a>builds these essential skills.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>A strong testing strategy must include regular checks for non-working or outdated links. These issues may look small, but they impact user trust, search visibility, and business growth in a big way. Automated validation with Selenium helps teams save time, avoid release delays, and deliver a smooth browsing experience for every user.<\/p>\n\n\n\n<p>If you want to gain real-world automation skills and learn how to build reliable validation scripts, enroll in H2K Infosys today. Our hands-on Selenium training will help you grow your career with confidence and practical knowledge.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A broken link disrupts the user journey, blocks conversions, reduces trust, and lowers search engine rankings. Companies lose up to 20% of customer trust when users land on dead pages, according to recent UX studies. QA teams must detect these issues before release. This is where Selenium testing helps teams quickly scan websites, identify broken [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":16541,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[43],"tags":[1555],"class_list":["post-16534","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-selenium-tutorials","tag-broken-links-in-selenium"],"_links":{"self":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/16534","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/comments?post=16534"}],"version-history":[{"count":8,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/16534\/revisions"}],"predecessor-version":[{"id":32601,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/posts\/16534\/revisions\/32601"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media\/16541"}],"wp:attachment":[{"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/media?parent=16534"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/categories?post=16534"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.h2kinfosys.com\/blog\/wp-json\/wp\/v2\/tags?post=16534"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}