How to identify broken links in Selenium WebDriver: Python Example
Here's an updated Selenium Python program that checks for both missing and invalid links: import requests from selenium import webdriver # Create a new instance of the Firefox driver driver = webdriver.Firefox() # Navigate to the web page you want to check driver.get( "http://www.example.com" ) # Find all the links on the page links = driver.find_elements_by_tag_name( "a" ) # Loop through each link and check if it is missing or invalid for link in links: href = link.get_attribute( "href" ) if href is None or href == "" : print ( "Missing link: " , link.text) else : response = requests.head(href) if response.status_code >= 400 : print ( "Invalid link: " , href) # Close the browser window driver.quit() This updated program still uses Selenium to navigate to the web page and find all the links. However, it also ...