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 ‘href’ value to obtain the hyperlinks and then analyze the response received when used in driver.get() method.