Skip to content

Instantly share code, notes, and snippets.

@webdevwilson
Created February 4, 2012 20:22
Show Gist options
  • Save webdevwilson/1739887 to your computer and use it in GitHub Desktop.
Save webdevwilson/1739887 to your computer and use it in GitHub Desktop.
HtmlUnit getting started
// from HtmlUnit getting started
final WebClient webClient = new WebClient();
final HtmlPage page = webClient.getPage("http://htmlunit.sourceforge.net");
final DOMNodeSelector cssSelector = new DOMNodeSelector(page.getDocumentElement());
final Set elements = cssSelector.querySelectorAll("div.section h2");
final Node first = elements.iterator().next();
assertThat(first.getTextContent(), equalTo("HtmlUnit"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment