Dec 9, 2019 in Testing

Q: Explain how can you find broken links in a page using Selenium WebDriver?

1 Answer

Dec 9, 2019
This is a tricky question which the interviewer might present to you. He can provide a situation wherein there are 20 links in a web page, and we have to verify which of those 20 links are working and how many are not working (broken).

As you have to verify the working of every link, the workaround is that you need to send HTTP requests to all of the links on the web page and analyze the response. Whenever you use driver.get() method to navigate to a URL, it will respond with a status of 200 – OK. This indicates that the link is working and it has been obtained. Whereas any other status indicates that the link is broken.

Let’s now understand how to do that.

First, we have to use the anchor tags <a> to determine the different hyperlinks on the web page. For every <a> tag, we can use the attribute ‘****’ value to obtain the hyperlinks and then analyze the response received when used in driver.get() method.
Click here to read more about Loan/Mortgage
Click here to read more about Insurance

Related questions

Aug 22, 2019 in Selenium
Aug 19, 2019 in Selenium
Jan 17 in Jenkins