From: Karl <ka...@we...> - 2005-07-19 00:13:13
|
Hi everyone. I've recently built a web navigation tool that sits on top of htmlunit to make the dom navigation a bit easier. With it you can chain navigations together to get to the element you are looking for quickly, or to check if something exists. For example: WebNavigator nav = new WebNavigator(); nav.gotoUrl(someUrl); // do a deep search from the body's child elements onward, for an // element that has id "randomLink" and attempt to activate it. // This assumes that the element can be activated (i.e. an anchor or // button). nav.bodyChildren().deep().id("randomLink").activate(); Another navigation: // Get the div elements that are directly below the body tag, find the // one with id "section1", get the form elements from its children, // find the one that has id "formA", then get the first input element // underneath it and set it to "10". nav.bodyChildren().div().id("section1").children().form().id("formA").children().input().setValue(10); Using regular expressions: // Do a deep search for any element on the page that is an anchor, // then narrow down the search to an anchor that has viewable text // containing "random" at any point, and tell me if it exists nav.page().deep().a().pattern().text(".*random.*").exists(); Anyway I've set up a sourceforge project for it at http://navigation.sourceforge.net Have a look if you think it might be useful. |