How to find all broken/invalid links from a webpage using python selenium?

0 votes
How to find all broken/invalid links from a webpage using python selenium?
Jul 30, 2019 in Selenium by Ruchi
815 views

1 answer to this question.

0 votes

Hi Ruchi, following lines of code can help you in finding qall broken/invalid links on a webpage using python selenium webdriver:

webdriver.get(PAGEURL)

links = webdriver.find_elements_by_css_selector("a")

for link in links:

  if (requests.head(link.get_attribute('href')).status_code == 200):
  print("Valid link")
  else:
  print("Broken link")
answered Jul 31, 2019 by Anvi
• 14,090 points

Related Questions In Selenium

0 votes
2 answers
0 votes
1 answer

How to check all checkboxes on a webpage using Selenium?

Hey Jenny, to check all the checkboxes ...READ MORE

answered Jun 25, 2019 in Selenium by Suraj
317 views
0 votes
1 answer
0 votes
1 answer

How to get all options of a dropdown on a webpage using Selenium Webdriver?

Hey Joel, you can use following lines ...READ MORE

answered Jul 15, 2019 in Selenium by Abha
• 27,930 points
543 views
0 votes
1 answer

How to Hover using Mouse in python using Webdriver

from selenium.webdriver.common.action_chains import ActionChains def hover(self): ...READ MORE

answered Aug 8, 2018 in Selenium by Meci Matt
• 9,460 points
1,071 views
0 votes
1 answer

How to launch browsers using Python-Selenium?

Hey Nikita, to launch browser in Python-Selenium, ...READ MORE

answered May 24, 2019 in Selenium by Anvi
• 14,090 points
113 views
0 votes
1 answer
0 votes
1 answer