I'm trying to analyze a website (shop.lego.com), but when using either click or getPage on the anchor (corresponding to the text "View All") the HtmlPage produced is the same as the original page. I believe the problem has to do with a HtmlUnit running a javascript on the page (javascript is enabled on the webclient).
The specific webpage is http://shop.lego.com/en-CA/Sales-And-Deals. I create a webClient with the following settings:
WebClient webClient = new WebClient(BrowserVersion.FIREFOX_38); webClient.getOptions().setThrowExceptionOnScriptError(false); webClient.getOptions().setJavaScriptEnabled(true); webClient.getOptions().setActiveXNative(true); webClient.getOptions().setAppletEnabled(true); webClient.getOptions().setActiveXNative(true); webClient.getOptions().setCssEnabled(true); webClient.getOptions().setDoNotTrackEnabled(false); webClient.getOptions().setGeolocationEnabled(true); webClient.getOptions().setPopupBlockerEnabled(false); webClient.getOptions().setPrintContentOnFailingStatusCode(true); webClient.getOptions().setRedirectEnabled(true); webClient.getCache().clear(); webClient.getCache().setMaxSize(0); webClient.setAjaxController(new NicelyResynchronizingAjaxController()); webClient.getCookieManager().setCookiesEnabled(true);
Then I open the page (I put loop in place to ensure that the page returned is an Html page), and retrieve the anchor.
final URL url = new URL("http://shop.lego.com/en-CA/Sales-And-Deals"); int count = 0; Page pageOri = webClient.getPage(url); while (count < 5 && !(pageOri instanceof HtmlPage)) { pageOri = webClient.getPage(url); count++; System.out.println("Read Attempt #" + count + " failed."); } final HtmlPage page = (HtmlPage) pageOri; HtmlAnchor choosen = page.getAnchorByText("View All");
Then I click on the anchor and print the text representation, but the text representation is the same as the original.
HtmlPage allResults = (HtmlPage) choosen.getPage(); System.out.println(allResults.asText());
Diff:
setThrowExceptionOnScriptError(false)
hides an underlying error.Test case added in NativeObjectTest.setPrototype()
test was moved to XMLHttpRequest2Test.readPropertyFromPrototypeShouldThrow()