maven
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.19</version>
</dependency>
try (final WebClient webClient = new WebClient()) {
final HtmlPage htmlPage = webClient.getPage("http://www.google.com");
Assert.assertEquals("Google", htmlPage.getTitleText());
Assert.assertTrue(htmlPage.asText().contains("Google+"));
final HtmlForm searchForm = htmlPage.getFormByName("f");
final HtmlTextInput textField = searchForm.getInputByName("q");
textField.setValueAttribute("google");
final HtmlSubmitInput submitButton = searchForm.getInputByName("btnG");
final HtmlPage searchPage = submitButton.click();
Assert.assertTrue(searchPage.asText().contains("Search Options"));
}