Checking that links are valid

It's actually pretty simple to check links. All you need to do is find the link on the page, extract a URL from its href attribute, and then check to see if sending an HTTP GET request to that URL results in a valid response.

Let's create some code to do this for us.

First of all, we are going to need to add some dependencies to our POM:

<properties>    <commons-io.version>2.6</commons-io.version>    <httpclient.version>4.5.5</httpclient.version></properties><dependency>    <groupId>org.apache.httpcomponents</groupId>    <artifactId>httpclient</artifactId>    <version>${httpclient.version}</version>    <scope>test</scope></dependency><dependency>    <groupId>commons-io</groupId>    <artifactId>commons-io</artifactId>    <version>${commons-io.version} ...

Get Mastering Selenium WebDriver 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.