From: Marc G. <mgu...@ya...> - 2005-06-10 07:59:17
|
contentWindow is not currently implemented. There is already an opened RFE for that https://sourceforge.net/tracker/index.php?func=detail&aid=1210688&group_id=47038&atid=448269 Marc. Shanbhag, Gautam wrote: > This looks more of a Rhino issue than a htmlunit issue. > I am having problems using the document element inside a iframe > through Javascript. Is there any workaround to this problem? > > Thanks, > Gautam > > Heres the code and the output contains the html I used. > > > import java.io.IOException; > import java.net.MalformedURLException; > import java.net.URL; > > import org.apache.commons.httpclient.cookie.CookiePolicy; > import org.apache.commons.httpclient.params.DefaultHttpParams; > import org.apache.commons.httpclient.params.HttpMethodParams; > > import com.gargoylesoftware.htmlunit.BrowserVersion; > import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; > import com.gargoylesoftware.htmlunit.WebClient; > import com.gargoylesoftware.htmlunit.html.HtmlButton; > import com.gargoylesoftware.htmlunit.html.HtmlButtonInput; > import com.gargoylesoftware.htmlunit.html.HtmlPage; > > public class TestHtmlUnit > { > public static void main(String args[]) > { > final WebClient webClient = new WebClient(BrowserVersion.INTERNET_EXPLORER_6_0); > webClient.setJavaScriptEnabled(true); > System.setProperty("apache.commons.httpclient.cookiespec", CookiePolicy.BROWSER_COMPATIBILITY); > DefaultHttpParams.getDefaultParams().setBooleanParameter(HttpMethodParams.SINGLE_COOKIE_HEADER, true); > > try { > final HtmlPage page = (HtmlPage)webClient.getPage( new URL("file:///c:/gautam/gs.html") ); > String out = page.getWebResponse().getContentAsString(); > System.out.println("Page:"+out); > HtmlButtonInput hb= (HtmlButtonInput)page.getHtmlElementById("dee"); > hb.click(); > > } catch (FailingHttpStatusCodeException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } catch (MalformedURLException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } catch (IOException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } > > > } > > > > } > > > > > > > Output: > > Page: > <html> > <head> > <script language="JavaScript" > > function dada() > { > var iframe=document.getElementById("gautam"); > iframe.contentWindow.document.write("hello"); > } > </script> > </head> > > <body> > > <IFRAME id="gautam" src="" width="800" height="200"></IFRAME> > <input type="button" id="dee" onclick="dada()"> > </body> > </html> > > > Exception in thread "main" ======= EXCEPTION START ======== > EcmaError: lineNumber=[4] column=[0] lineSource=[null] name=[TypeError] sourceName=[Embedded script] message=[TypeError: Cannot read property "document" from undefined (Embedded script#4)] > com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot read property "document" from undefined (Embedded script#4) > at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:340) > at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:759) > at com.gargoylesoftware.htmlunit.html.ClickableElement.click(ClickableElement.java:107) > at amazon.gautams.test.TestHtmlUnit.main(TestHtmlUnit.java:32) > Enclosed exception: > org.mozilla.javascript.EcmaError: TypeError: Cannot read property "document" from undefined (Embedded script#4) > at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3240) > at org.mozilla.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3230) > at org.mozilla.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3246) > at org.mozilla.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3265) > at org.mozilla.javascript.ScriptRuntime.undefReadError(ScriptRuntime.java:3278) > at org.mozilla.javascript.ScriptRuntime.getObjectProp(ScriptRuntime.java:1319) > at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2744) > at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2164) > at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:140) > at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:304) > at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:2769) > at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2145) > at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:140) > at com.gargoylesoftware.htmlunit.javascript.host.EventHandler.call(EventHandler.java:88) > at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:335) > at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:759) > at com.gargoylesoftware.htmlunit.html.ClickableElement.click(ClickableElement.java:107) > at amazon.gautams.test.TestHtmlUnit.main(TestHtmlUnit.java:32) > == CALLING JAVASCRIPT == > function () { > [native code, arity=0] > } > > ======= EXCEPTION END ======== > > > -----Original Message----- > From: htm...@li... [mailto:htm...@li...] On Behalf Of Brad Clarke > Sent: Thursday, June 09, 2005 9:18 AM > To: htm...@li... > Subject: Re: [Htmlunit-user] Problem using htmlunit/rhino with dom > > I have no idea what you're trying to do but SimpleScriptable (and everything under the javascript package) is internal code. From the package.html: > > "Classes in this package are specific for the javascript engine - users of HtmlUnit shouldn't need anything in this package." > > Then there's the fact that creating a SimpleScriptable directly doesn't seem like it would do much good anyway (it should probably be an abstract class but since it isn't really public API...). > > Brad C > > --- "Ulaszek, Ryan" <Rya...@in...> wrote: > > >>Hello, >> >>I am trying to load some java script buisness logic into a java app >>using rhino and ran into a problem with calls being made to >>setInterval which is a DOM function. I am trying to use html units >>SimpleScriptable but am not sure on how to use it. I am hoping that >>using that object will provide DOM support. Is this true? This is >>what I am trying to do with rhino. Anyone have suggestions on how to >>do this with htmlunit? Any help is greatly appreciated. >> >>Thanks >> >>public void getCalcs(Context cx) >>{ >> ScriptableObject shell = new ScriptableObject(); >> >> Object fObj2 = shell .get("setFormField", shell ); >> if (!(fObj2 instanceof Function)) { >> System.out.println("field is undefined or not a function."); >> } else { >> Object functionArgs[] = { "muniIntNonAz", "3","azAgi" }; >> Function f2 = (Function)fObj2; >> Object result = f2.call(cx, shell , shell , functionArgs); >> String report = Context.toString(result); >> System.out.println(report); >> } >>} >> >>I tried this >> >>public void getCalcs(Context cx) >>{ >> SimpleScriptable shell = new SimpleScriptable(); >> >> Object fObj2 = shell .get("setFormField", shell ); >> if (!(fObj2 instanceof Function)) { >> System.out.println("field is undefined or not a function."); >> } else { >> Object functionArgs[] = { "muniIntNonAz", "3","azAgi" }; >> Function f2 = (Function)fObj2; >> Object result = f2.call(cx, shell , shell , functionArgs); >> String report = Context.toString(result); >> System.out.println(report); >> } >>} >> >> >>Ryan Ulaszek | QA Software Automation Engineer: | Intuit, Inc. >>858-525-9560 >> >> > > > > > ------------------------------------------------------- > This SF.Net email is sponsored by: NEC IT Guy Games. How far can you shotput a projector? How fast can you ride your desk chair down the office luge track? > If you want to score the big prize, get to know the little guy. > Play to win an NEC 61" plasma display: http://www.necitguy.com/?r=20 _______________________________________________ > Htmlunit-user mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/htmlunit-user > > > ------------------------------------------------------- > This SF.Net email is sponsored by: NEC IT Guy Games. How far can you shotput > a projector? How fast can you ride your desk chair down the office luge track? > If you want to score the big prize, get to know the little guy. > Play to win an NEC 61" plasma display: http://www.necitguy.com/?r > _______________________________________________ > Htmlunit-user mailing list > Htm...@li... > https://lists.sourceforge.net/lists/listinfo/htmlunit-user > |