โ† Back to libraryQuestion 157 of 273
๐ŸงชSeleniumIntermediate

Handling Broken Links

๐Ÿ“– Detailed Explanation:

Selenium alone can't find broken links; it only clicks them. To verify links, we use the Java `HttpURLConnection` class to send HTTP HEAD requests to each URL and check the HTTP status code (200 = OK, 404 = Not Found, 500 = Server Error, etc.). This is much faster than loading every page.

๐ŸŒ Real-World Example:

Checking a link with Selenium is like actually visiting every website. Checking with HttpURLConnection is like asking a robot to quickly verify the link works without loading the whole page.

๐ŸŽฏ Scenario-Based Interview Question:

How do you check for broken links on a page with 100 links without clicking each one?