O'Reilly logo

Mastering Selenium WebDriver 3.0 by Mark Collin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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} ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required