Skip to content

Instantly share code, notes, and snippets.

@webdevwilson
Created February 4, 2012 18:53
Show Gist options
  • Save webdevwilson/1739459 to your computer and use it in GitHub Desktop.
Save webdevwilson/1739459 to your computer and use it in GitHub Desktop.
jquery HtmlUnit base class
public class WebTestBase {
protected WebClient webClient;
protected HtmlPage htmlPage;
protected void goTo(final String url){
return (HtmlPage)webClient.getPage(url);
}
protected List $(final String cssSelector) {
final DOMNodeSelector cssSelector = new DOMNodeSelector(htmlPage.getDocumentElement());
final Set nodes = cssSelector.querySelectorAll("div.section h2");
// for some reason Set cannot be cast to Set?
final List elements = new ArrayList(nodes.size());
for (final Node node : nodes) {
elements.add((HtmlElement)node);
}
return elements;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment