From: smk s. <ste...@gm...> - 2014-02-05 09:19:50
|
Hi As Sreenadh mentioned not every response is an HtmlPage object however all of them are Page objects. Thus you have to typecast accordingly. Check the following code wchich returns the source as String according to the type of the response. Page pageSource = webClient.getPage("http://example.com"); String pageSourceString = getPageSource(pageSource); public static String getPageSource(Page page) { if(page instanceof HtmlPage) { return ((HtmlPage)page).asXml(); } else if(page instanceof JavaScriptPage) { return ((JavaScriptPage)page).getContent(); } else if(page instanceof TextPage) { return ((TextPage)page).getContent(); } else //page instanceof UnexpectedPage { return ((UnexpectedPage)page).getWebResponse().getContentAsString(); } } >From the above example you can see that there are 4 different types of Pages that webClient returns. The method used here returns the string of the source however you can modify the code to your needs according to the instance is returned. Stergios 2014-02-05 Ahmed Ashour <asa...@ya...>: > Hi, > > This happens when HtmlUnit determines the content type of this page to be > plain text, not HTML. > > Please send the details of the complete case. > > Ahmed > ------------------------------ > *From:* Sreenath <sre...@gm...> > *To:* "htm...@li..." < > htm...@li...> > *Sent:* Wednesday, February 5, 2014 11:53 AM > *Subject:* [Htmlunit-user] java.lang.ClassCastException: > com.gargoylesoftware.htmlunit.TextPage cannot be cast to > com.gargoylesoftware.htmlunit.html.HtmlPage > > Hello, > > I have tried to load pme web page url and did submission of the page, > second page is not getting loaded due to following issue. > > > java.lang.ClassCastException: com.gargoylesoftware.htmlunit.TextPage > cannot be cast to com.gargoylesoftware.htmlunit.html.HtmlPage > > Note: my page is type of HtmlPage, not able to cast to HtmlPage > > Please advice why the second page is coming as type of > com.gargoylesoftware.htmlunit.TextPage, and how can assign to HtmlPage > type the same. > > Thanks in Advance > Sreenadh > > > > ------------------------------------------------------------------------------ > Managing the Performance of Cloud-Based Applications > Take advantage of what the Cloud has to offer - Avoid Common Pitfalls. > Read the Whitepaper. > > http://pubads.g.doubleclick.net/gampad/clk?id=121051231&iu=/4140/ostg.clktrk > _______________________________________________ > Htmlunit-user mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/htmlunit-user > > |