1.

How would you find broken links on a webpage with the Webdriver?

Answer»

Links or URLS which are not reachable or FUNCTIONING are broken links due to some error.

There are different status codes for HTTP which are having different purposes. 2XX is valid request status and the URL will always have status 2XX. Status 4XX and 5XX are for invalid HTTP request out of which 4XX status code is for client-side error and 5XX status code are for server response error.

It is not possible to confirm that the link is working or not till we click on the link and confirm it.

It is always GOOD practice to make sure that there are no broken links because the end-user should not land into an error page.

You can not check all links manually, because each web page may have a large number of links & manual process has to be repeated for all pages. It will be a tedious task.

With Selenium, we can automate the process.

  • First, collect all links on the web page BASED on a tag.
  • Then send an HTTP request for the link and read the HTTP response code.
  • Based on the HTTP response code determine whether the link is valid or broken
  • Repeat this for all the links CAPTURED.


Discussion

No Comment Found