All of the examples I see for htmlunit retrieve the HTML from website via a URL using getPage.
WebClient webClient = new WebClient();
HtmlPage page = webClient.getPage("http://htmlunit.sourceforge.net");
I’m holding an HTML fragment in a string variable and can’t find a way to give it the HTML from a variable.
I’ve tried casting the String to HtmlPage but that doesn’t work.
HtmlPage page = (HtmlPage) htmlFragment
Perhaps you could write the HTML fragment (possibly wrapped in the standard html/head/body tags) into a temp file and use its URL for your web client. For example (untested):
Alternatively, you might be able to construct your own
HtmlPagewith a phony URL and ad-hocWebResponseandWebWindowbut that might require a lot of hacking.