From: <ec...@at...> - 2003-06-25 13:56:20
|
Mike, I have seen many having same problem with Select control which triggers an onChange javascript event. Some one in the forum mentioned about having this problem of "this.form" in the javascript code of the onChange event. I think I have the same problem with "this.name". The focus needs to be set to the select control. Below are stack traces with different js.jar files. Your help would be greatly appreciated. Besides this problem, htmlunit works great.!!!. Thanks in advance.. Here is my htmlunit code: HtmlSelect hs=form1.getSelectByName("PageRenderer.Menu"); pg5=(HtmlPage)hs.setSelectedAttribute("action.manage",true); Here is source code for the select control: <select name="PageRenderer.Menu" class="MnuJmp" onkeypress="javascript:this.onChange();" onchange="javascript:var a=document.PageRenderer.elements[this.name];for (i=0; i<a.length; i++) {a[i].selectedIndex=this.selectedIndex;};javascript:var f=document.PageRenderer;if (f != null) {f.action='../renderer/PageRenderer?PageRenderer.DefaultHref=&jato.pageSession=Anja.....';f.submit();}"> <option class="MnuJmpOpt" value="— Actions —">— Actions —</option> <option class="MnuJmpOpt" value="group.add">Add To Group</option> <option class="MnuJmpOpt" value="create.alias">Create Alias</option> <option class="MnuJmpOpt" value="action.manage">Manage</option> </select> With the js.jar that comes with htmunit 1.2.2, I get the following error: 1) testManageAsset(HtmlUnitTestCase2)======= EXCEPTION START ======== Exception class=[org.mozilla.javascript.EvaluatorException] com.gargoylesoftware.htmlunit.ScriptException: The undefined value has no properties. at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:199) at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptIfPossible(HtmlPage.java:767) at com.gargoylesoftware.htmlunit.html.HtmlSelect.setSelectedAttribute(HtmlSelect.java:133) at HtmlUnitTestCase2.testManageAsset(HtmlUnitTestCase2.java:69) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at HtmlUnitTestCase2.main(HtmlUnitTestCase2.java:87) Enclosed exception: org.mozilla.javascript.EvaluatorException: The undefined value has no properties. at com.gargoylesoftware.htmlunit.javascript.StrictErrorReporter.runtimeError(StrictErrorReporter.java:84) at org.mozilla.javascript.Context.reportRuntimeError(Context.java:591) at org.mozilla.javascript.Context.reportRuntimeError(Context.java:630) at org.mozilla.javascript.Context.reportRuntimeError0(Context.java:600) at org.mozilla.javascript.Undefined.reportError(Undefined.java:138) at org.mozilla.javascript.Undefined.getPrototype(Undefined.java:100) at org.mozilla.javascript.ScriptableObject.getBase(ScriptableObject.java:1585) at org.mozilla.javascript.ScriptableObject.putProperty(ScriptableObject.java:1473) at org.mozilla.javascript.ScriptRuntime.setProp(ScriptRuntime.java:842) at org.mozilla.javascript.gen.c47.call(Wrapper definition for onChange handler:1) at org.mozilla.javascript.optimizer.OptRuntime.callSimple(OptRuntime.java:275) at org.mozilla.javascript.gen.c49.call(onChange handler:1) at org.mozilla.javascript.gen.c49.exec(onChange handler) at org.mozilla.javascript.Context.evaluateReader(Context.java:820) at org.mozilla.javascript.Context.evaluateString(Context.java:784) at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:191) at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptIfPossible(HtmlPage.java:767) at com.gargoylesoftware.htmlunit.html.HtmlSelect.setSelectedAttribute(HtmlSelect.java:133) at HtmlUnitTestCase2.testManageAsset(HtmlUnitTestCase2.java:69) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at HtmlUnitTestCase2.main(HtmlUnitTestCase2.java:87) == CALLING JAVASCRIPT == GargoyleWrapper2() ======= EXCEPTION END ======== WITH THE LATEST js.jar file from mozilla I get the following error: There was 1 error: 1) testManageAsset(HtmlUnitTestCase2)======= EXCEPTION START ======== EcmaError: lineNumber=[1] column=[0] lineSource=[GargoyleWrapper2()] name=[TypeError] sourceName=[Wrpper definition for onChange handler] message=[Cannot set property "selectedIndex" of undefined to ""] errorObject=[TypeError: Cannot set property "selectedIndex" of undefined to "3"] com.gargoylesoftware.htmlunit.ScriptException: Cannot set property "selectedIndex" of undefined to "" at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:19) at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptIfPossible(HtmlPage.java:767 at com.gargoylesoftware.htmlunit.html.HtmlSelect.setSelectedAttribute(HtmlSelect.java:133) at HtmlUnitTestCase2.testManageAsset(HtmlUnitTestCase2.java:70) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at HtmlUnitTestCase2.main(HtmlUnitTestCase2.java:88) Enclosed exception: TypeError: Cannot set property "selectedIndex" of undefined to "3" (Wrapper definition for onChange andler; line 1) at org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:609) at org.mozilla.javascript.NativeGlobal.constructError(NativeGlobal.java:556) at org.mozilla.javascript.NativeGlobal.undefWriteError(NativeGlobal.java:587) at org.mozilla.javascript.ScriptRuntime.setProp(ScriptRuntime.java:826) at org.mozilla.javascript.gen.c47.call(Wrapper definition for onChange handler:1) at org.mozilla.javascript.optimizer.OptRuntime.callSimple(OptRuntime.java:272) at org.mozilla.javascript.gen.c49.call(onChange handler:1) at org.mozilla.javascript.gen.c49.exec(onChange handler) at org.mozilla.javascript.Context.evaluateString(Context.java:773) at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.execute(JavaScriptEngine.java:11) at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptIfPossible(HtmlPage.java:767 at com.gargoylesoftware.htmlunit.html.HtmlSelect.setSelectedAttribute(HtmlSelect.java:133) at HtmlUnitTestCase2.testManageAsset(HtmlUnitTestCase2.java:70) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at HtmlUnitTestCase2.main(HtmlUnitTestCase2.java:88) == CALLING JAVASCRIPT == GargoyleWrapper2() ======= EXCEPTION END ======== |