How to Find Broken links in an Application using Selenium Webdriver....?

1,404 views
Skip to first unread message

neeraj bakhtani

unread,
Sep 14, 2013, 2:52:39 AM9/14/13
to seleniu...@googlegroups.com
Hi,
How can we find broken links or Broken images in an application by using Selenium Webdriver....?

unni krishnan pr

unread,
Sep 18, 2013, 5:52:12 AM9/18/13
to seleniu...@googlegroups.com
Hi,

You can use webdriver to get the "href"  values of all the "a" (hyperlink) elements. Once u have all the links with you, you can use Apache Http Client to sent a "get" request through code. By checking the response code (whether it is a 200 or not), you can say whether the link is broken or not.
Message has been deleted

Omkar Kolekar

unread,
Jan 15, 2014, 5:41:05 AM1/15/14
to seleniu...@googlegroups.com


How can we find broken links or Broken images in an application by using Selenium Webdriver....?

pls share me the code....

ra cras

unread,
Jan 15, 2014, 7:51:09 AM1/15/14
to seleniu...@googlegroups.com
With selenium I don't know, but I use Xenu

neeraj bakhtani

unread,
Jan 15, 2014, 8:04:11 AM1/15/14
to seleniu...@googlegroups.com
Find the SOlution here

http://bugreaper.blogspot.in/2013/09/find-broken-images-for-application-or.html

Join the Blog and if you like the post pls comment....:)


--
You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/nCBLoagMKIs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/e441a419-97e3-4fae-9a99-33f24367cee3%40googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.

Omkar Kolekar

unread,
Jan 15, 2014, 11:44:35 PM1/15/14
to seleniu...@googlegroups.com
Thank you dear..............
i will check and let u know



Omkar Kolekar

unread,
Jan 16, 2014, 12:17:08 AM1/16/14
to seleniu...@googlegroups.com
That code is not working on broken links.............and even for 404 error.........
pls help ........

Amit Sawant

unread,
Sep 29, 2015, 10:10:26 AM9/29/15
to Selenium Users
Please help me with solution to find out broken images and links.


On Saturday, 14 September 2013 12:22:39 UTC+5:30, neeraj bakhtani wrote:

Doug Dragon

unread,
Sep 30, 2015, 9:15:16 AM9/30/15
to Selenium Users
Here's something I did in the past that worked well for me. It's all in Python but you can get the gist:

# First, we'll use selenium to get the page and grab all the links and images from the page:
from selenium import webdriver
driver
= webdriver.Firefox()
driver
.get("
http://the-internet.herokuapp.com/")
links
= driver.find_elements_by_css_selector("a")
images
= driver.find_elements_by_css_selector("img")

# Now we'll hit each of the URLS using the head request from the Python Requests library
import requests
for link in links:
    r
= requests.head(link.get_attribute('href')
   
print(r.status_code == 200)
# Do the same with the images
for image in images:
    r
= requests.head(image.get_attribute('src')
   
print(r.status_code == 200)



I hope this helps,

-Doug

Doug Dragon

unread,
Sep 30, 2015, 9:28:40 AM9/30/15
to Selenium Users
You could alter the code to show ONLY the bad links (not 200):

for link in links:
    r
= requests.head(link.get_attribute('href')
    if r.status_code != 200:
       
print(link.get_attribute('href')
Reply all
Reply to author
Forward
0 new messages