From: Mehrdad R. <rez...@ya...> - 2008-02-07 19:59:05
|
Hi Everyone, I've been running into great difficult loading a page which includes iframes. I've been reading all the posts regarding problems with iframe, but they all seem to date to 2006 or early 2007; so, I'm hoping that someone has already found a solution. In my code, based on whether I disable JavaScript or enable it two different errors happen (note that for my situation,I do without JavaScript if it solves my problem). My code has nothing complicated, it just gets a page, and that's where the erorr happens. And also as you will see from the log that I have included below, these are all just iframes which display some adds and if I could somehow just ignore them or not download them, it would be great. Here's my code: ______________________ wc = new WebClient(BrowserVersion.INTERNET_EXPLORER_6_0); wc.setJavaScriptEnabled(true); wc.setCookiesEnabled(true); wc.setThrowExceptionOnScriptError(false); wc.setRedirectEnabled(true); wc.setRefreshHandler(new ThreadedRefreshHandler()); DefaultJSDialogWindowHandler jsPopupHanlder = new DefaultJSDialogWindowHandler(); wc.setAlertHandler(jsPopupHanlder); wc.setConfirmHandler(jsPopupHanlder); wc.setPromptHandler(jsPopupHanlder); HtmlPage loginPage = null; loginPage = (HtmlPage) wc.getPage("http://my.monster.com/Login.aspx"); _____________________ If I enable the Javascript, only one iframe of one of the ads is loaded onto the page. But if I disable the JavaScript, then I get a NullPointerException and the log below (Note that I have included only the part of the log file which is relevent in order to make reading it easy, but I do have the longer version of the log. ____________________________ [06 Feb 2008 22:15:04}] [DEBUG] [CLASS: com.gargoylesoftware.htmlunit.WebClient] "Get page for window named 'AdFrame_1_MasterPage1:HeaderContent:Header_Default:BannerAd1', using We bRequestSettings[<url="about:blank", SubmitMethod[name=get], EncodingType[name=application/x-www-for m-urlencoded], [], {}, null>]" ============================ [06 Feb 2008 22:15:21}] [DEBUG] [CLASS: com.gargoylesoftware.htmlunit.WebClient] "Get page for window named 'AdFrame_1_MasterPage1:BodyContent:RightOfLoginAd', using WebRequestSett ings[<url="about:blank", SubmitMethod[name=get], EncodingType[name=application/x-www-form-urlencoded ], [], {}, null>]" ============================ [06 Feb 2008 22:15:52}] [DEBUG] [CLASS: com.gargoylesoftware.htmlunit.WebClient] "Get page for window named 'AdFrame_1_MasterPage1:HeaderContent:Header_Default:BannerAd1', using We bRequestSettings[http://ads.monster.com/html.ng/site=m ons&affiliate=mons&app=cc&size=728x90&pp=1&path=/Channels/NMONS/login.aspx&dcpc=&ge=-1&tileid=9186' + parent.segQS );", SubmitMethod[name=get], EncodingType[name=application/x-www-form-urlencoded], [] , {Referer=http://my.monster.com/Login.aspx}, null>]" ============================ java.lang.NullPointerException at com.gargoylesoftware.htmlunit.WebClient.makeWebResponseForJavaScriptUrl(WebClient.java:1331) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:327) at com.gargoylesoftware.htmlunit.html.BaseFrame.loadInnerPageIfPossible(BaseFrame.java:135) at com.gargoylesoftware.htmlunit.html.BaseFrame.loadInnerPage(BaseFrame.java:108) at com.gargoylesoftware.htmlunit.html.HtmlPage.loadFrames(HtmlPage.java:1497) at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:147) at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:453) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:343) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:397) at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:384) ____________________________ Note that the page includes only two iframes and it seems that the frame called AdFrame_1_MasterPage1:HeaderContent:Header_Default:BannerAd1 is loaded a first time with no problem, and then it is loaded a second time and that's when the page loading runs intotrouble. I appreciate it if anyone could give me a feed back as to how to solve this problem. Any suggestion would be greatly appreciated. Thanks, Orod ____________________________________________________________________________________ Looking for last minute shopping deals? Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping |
From: Ahmed A. <asa...@ya...> - 2008-02-08 11:09:02
|
Dear Mehrdad, First please use latest snapsho from http://build.canoo.com/htmlunit. Second, the following code works without any errors, please provide a producible test case. ----------------------------- WebClient wc = new WebClient(BrowserVersion.INTERNET_EXPLORER_6_0); wc.setJavaScriptEnabled(true); wc.setCookiesEnabled(true); wc.setThrowExceptionOnScriptError(false); wc.setRedirectEnabled(true); wc.setRefreshHandler(new ThreadedRefreshHandler()); HtmlPage loginPage = null; loginPage = (HtmlPage) wc.getPage("http://my.monster.com/Login.aspx"); ----------------------------- If you found an error, it would be really helpful to try to isolate the root cause. Hope that helps, Ahmed ____________________________________________________________________________________ Looking for last minute shopping deals? Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping |
From: Orod <rez...@ya...> - 2008-02-11 00:59:07
|
Hi Ahmed, Thanks for your reply. Unfortunately, I got sidetracked, and didn't check back to see your reply. The test that you had mentioned does pass, but if you check the page's source, then you'll see it is not the whole page, but only the content of one of the iframes in the page. I did download and used the latest build as you had suggested; however, now the page doesn't even include that iframe, but just empty. Per your suggestion, I have created the following test case that you can run and see the result yourself. Note that I am stumped in the first step since I can't even get the login page correctly, let alone navigate the page and set fields or click on any element. --------------------------- package core.biz.services.sites; import java.io.File; import java.io.FileWriter; import junit.framework.TestCase; import com.gargoylesoftware.htmlunit.BrowserVersion; import com.gargoylesoftware.htmlunit.Page; import com.gargoylesoftware.htmlunit.ThreadedRefreshHandler; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.html.HtmlAnchor; import com.gargoylesoftware.htmlunit.html.HtmlForm; import com.gargoylesoftware.htmlunit.html.HtmlInput; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.xml.XmlPage; public class IFrameTestCase extends TestCase { protected WebClient wc = null; private static final String LOGIN_PAGE = "http://my.monster.com/Login.aspx"; private static final String NAME_OF_LOGIN_FORM = "login_form"; private static final String NAME_OF_USER_NAME_FIELD = "login"; private static final String NAME_OF_PASSWORD_FIELD = "passwd"; private static final String NAME_OF_SUBMIT_BUTTON_ELEMENT = ".save"; @org.junit.Before protected void setUp() throws Exception { super.setUp(); wc = new WebClient(BrowserVersion.FIREFOX_2); wc.setJavaScriptEnabled(true); wc.setCookiesEnabled(true); wc.setThrowExceptionOnScriptError(false); wc.setRedirectEnabled(true); wc.setRefreshHandler(new ThreadedRefreshHandler()); } @org.junit.Test public void testCase1() { HtmlPage loginPage = null; try { try { loginPage = (HtmlPage) wc.getPage(LOGIN_PAGE); } catch(Exception e) { e.printStackTrace(); } assertNotNull(loginPage); printPageSource(loginPage, "monsterLoginPage_1.htm"); HtmlForm loginForm = loginPage.getFormByName(NAME_OF_LOGIN_FORM); assertNotNull(loginForm); HtmlInput userNameField = loginForm.getInputByName(NAME_OF_USER_NAME_FIELD); HtmlInput passwordField = loginForm.getInputByName(NAME_OF_PASSWORD_FIELD); assertNotNull(userNameField); assertNotNull(passwordField); userNameField.setValueAttribute("userName"); passwordField.setValueAttribute("password"); HtmlInput submitButton = loginForm.getInputByName(NAME_OF_SUBMIT_BUTTON_ELEMENT); printPageSource(loginPage, "monsterLoginPage_2.htm"); HtmlPage pageAfterLogin = (HtmlPage) submitButton.click(); printPageSource(pageAfterLogin, "monsterLoginPage_2.htm"); assertNotNull(pageAfterLogin); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); }//End of try/catch block. } @org.junit.After protected void tearDown() throws Exception { super.tearDown(); } /* just a utility method for saving the page source to a file */ protected void printPageSource(Page page, String fileNameToSaveTheSourceAs) { try { File fileToSavePageTo = new File(fileNameToSaveTheSourceAs); fileToSavePageTo.createNewFile(); FileWriter fileWriter = new FileWriter(fileToSavePageTo); if (page instanceof XmlPage) { fileWriter.write(((XmlPage) page).getContent()); } else if (page instanceof HtmlPage) { fileWriter.write(((HtmlPage) page).asXml()); } fileWriter.flush(); fileWriter.close(); //log.error(((HtmlPage) page).asXml()); } catch (Exception e) { e.printStackTrace(); } }//End of printPageSource(). }//End of class IFrameTestCase. -------------------------- -- View this message in context: http://www.nabble.com/Iframe-With-JavaScript-as-Src-attribute-tp15341965p15403832.html Sent from the HtmlUnit - General mailing list archive at Nabble.com. |
From: Ahmed A. <asa...@ya...> - 2008-02-13 06:25:39
|
Dear Mehrdad, As you long as you are subscriber to the list, you can use Nabble. Your message has been receieved. But answering it needs a lot of effort, if you want a quick one: Saying there is problem with "http://my.monster.com/Login.aspx" doesn't mean the root cause has been identified, it must be traced to find the offending line and make a reproducible tiny test case that demonstrates that. Only when we have a tiny case, it can be fixed. Since we don't have many resources, please try to identify the issue yourself, and submit a case similar to the ones at http://htmlunit.svn.sourceforge.net/viewvc/htmlunit/trunk/htmlunit/src/test/java/com/gargoylesoftware/htmlunit/html/HtmlElementTest.java?revision=2337&view=markup for instance. Please have a look at http://htmlunit.sourceforge.net/submittingBugs.html Hope that helps, Many thanks, Ahmed ----- Original Message ---- From: Mehrdad Rezai <rez...@ya...> To: htm...@li... Sent: Wednesday, February 13, 2008 3:45:33 AM Subject: Re: [Htmlunit-user] Iframe With JavaScript as Src attribute Is there a reason that my message and the test case I had posted is being ignored? I have posted my messages through my nabble.com's accounts, so I'm thinking may be you guys are not getting my messages for some reason. Looking for last minute shopping deals? Find them fast with Yahoo! Search. -----Inline Attachment Follows----- ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ -----Inline Attachment Follows----- _______________________________________________ Htmlunit-user mailing list Htm...@li... https://lists.sourceforge.net/lists/listinfo/htmlunit-user ____________________________________________________________________________________ Looking for last minute shopping deals? Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping |
From: Mehrdad <rez...@ya...> - 2008-02-13 21:05:05
|
Hi Ahmed, Thanks for your reply. I apologize if I appeared to be impatient; I'm new to the mailing list and don't know all the ins and out of it. In any case, I thought by test case you meant just a Junit test case that you can run and see the results. As long as I know there is no known and simple fix, I can look for more details and possibly solve the problem myself. I will post the problem and the solution as soon I have resolved the problem. Thanks, Mehrdad -- View this message in context: http://www.nabble.com/Iframe-With-JavaScript-as-Src-attribute-tp15341965p15467910.html Sent from the HtmlUnit - General mailing list archive at Nabble.com. |