From: smk s. <ste...@gm...> - 2014-02-05 10:11:50
|
Change this "TextPage = responseAfterClick = elementTocick.click();" To this "TextPage responseAfterClick = elementTocick.click();" 2014-02-05 smk smk <ste...@gm...>: > Hi > > The problem is that you initialize the page as HtmlPage and not as Page. > > Thus you should do > > *Page* page = webClient.getPage(request); //not HtmlPage > > and then after the click you can do the check of the response as > mentioned at the first response. > > page = elementTocick.click(); > > if(page instanceof TextPage) > ......... > else if( > ...... > > My opinion though is to assign a new Page object at the response after the > click > > e.g > > Page responseAfterClick = elementTocick.click(); > if(responseAfterClick instanceof TextPage) > ....... > else if ( > ....... > > and if you are sure that it always rerurns a TextPage then you can > initialize it as TextPage from the beginning > > TextPage = responseAfterClick = elementTocick.click(); > > Hope that helps > > Stergios > > > > 2014-02-05 Sreenadh VP <sre...@co...>: > > Hi, >> >> Thanks for your attention and response. >> >> I have following code >> >> WebRequest request = new WebRequest(new URL(Url)); >> >> HtmlPage page = webClient.getPage(request); >> >> HtmlButton elementTocick = (HtmlButton)page.getElementById("elementId"); >> >> page = elementTocick.click(); // fails with >> java.lang.ClassCastException: com.gargoylesoftware.htmlunit.TextPage cannot >> be cast to com.gargoylesoftware.htmlunit.html.HtmlPage >> >> Need to assign new page after click to* page* reference of type >> HtmlPage, how can do the the same? Please advice >> >> Sreenadh >> >> >> On Wed, Feb 5, 2014 at 2:49 PM, smk smk <ste...@gm...> wrote: >> >>> 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 >>>> >>>> >>> >>> >>> ------------------------------------------------------------------------------ >>> 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 >>> >>> >> > |