2 Replies Latest reply on Apr 27, 2009 1:12 AM by Gokhan Cetin

    EcmaError on clicking htmloption or htmlcheckbox...

    Gokhan Cetin Newbie

      Hi. I am making some tests for clicking options and checkboxes. However i have a problem like this. My code is as below.

      public void testSetAntiVirus()throws IOException
       {
       page=(HtmlPage)client.getContentPage();
       List<HtmlElement> lst=getElements(page, "option");
       if( ((HtmlOption)lst.get(0)).isSelected() )
       page=lst.get(1).click();
       else
       page=lst.get(0).click();
       HtmlElement elem=getElement(page, "input", "@value", "Save");
       click(client, page, elem);
       assertEquals("anti-virus-settings", server.getManagedBeanValue("#{Menu.active}"));
       }
      


      this line page=lst.get(1).click();
      throws the error.
      If first option is selected i will click the other and vice versa.

      My trace is like this



      ======= EXCEPTION START ========
      EcmaError: lineNumber=[0] column=[0] lineSource=[function () {] name=[TypeError] sourceName=[null] message=[TypeError: Cannot call method "onclick" of null]
      com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot call method "onclick" of null
      at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:534)
      at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:515)
      at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:507)
      at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:464)
      at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:992)
      at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeEventHandler(EventListenersContainer.java:164)
      at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:177)
      at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:574)
      at com.gargoylesoftware.htmlunit.html.HtmlElement$2.run(HtmlElement.java:936)
      at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:515)
      at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:507)
      at com.gargoylesoftware.htmlunit.html.HtmlElement.fireEvent(HtmlElement.java:941)
      at com.gargoylesoftware.htmlunit.html.HtmlElement.fireEvent(HtmlElement.java:916)
      at com.gargoylesoftware.htmlunit.html.HtmlInput.executeOnChangeHandlerIfAppropriate(HtmlInput.java:468)
      at com.gargoylesoftware.htmlunit.html.HtmlSelect.setSelectedAttribute(HtmlSelect.java:298)
      at com.gargoylesoftware.htmlunit.html.HtmlSelect.setSelectedAttribute(HtmlSelect.java:271)
      at com.gargoylesoftware.htmlunit.html.HtmlOption.setSelected(HtmlOption.java:84)
      at com.gargoylesoftware.htmlunit.html.HtmlOption.doClickAction(HtmlOption.java:219)
      at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1329)
      at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1288)
      at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1257)
      at com.endersys.surgate.SurgateTestCase.click(SurgateTestCase.java:119)
      at com.endersys.common.AntiVirusModuleTest.testSetAntiVirus(AntiVirusModuleTest.java:72)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at junit.framework.TestCase.runTest(TestCase.java:154)
      at junit.framework.TestCase.runBare(TestCase.java:127)
      at org.apache.cactus.internal.AbstractCactusTestCase.runBareServer(AbstractCactusTestCase.java:153)
      at org.apache.cactus.internal.server.AbstractWebTestCaller.doTest(AbstractWebTestCaller.java:119)
      at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody0(AbstractWebTestController.java:93)
      at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody1$advice(AbstractWebTestController.java:224)
      at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest(AbstractWebTestController.java)
      at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody2(ServletTestRedirector.java:101)
      at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody3$advice(ServletTestRedirector.java:224)
      at org.apache.cactus.server.ServletTestRedirector.doPost(ServletTestRedirector.java)
      at org.jboss.jsfunit.framework.JSFUnitServletRedirector.doPost(JSFUnitServletRedirector.java:46)
      at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody0(ServletTestRedirector.java:72)
      at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody1$advice(ServletTestRedirector.java:224)
      at org.apache.cactus.server.ServletTestRedirector.doGet(ServletTestRedirector.java)
      at org.jboss.jsfunit.framework.JSFUnitServletRedirector.doGet(JSFUnitServletRedirector.java:52)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.jboss.jsfunit.framework.JSFUnitFilter.doFilter(JSFUnitFilter.java:116)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
      at java.lang.Thread.run(Thread.java:619)
      Caused by: net.sourceforge.htmlunit.corejs.javascript.EcmaError: TypeError: Cannot call method "onclick" of null
      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3654)
      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3632)
      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3660)
      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3679)
      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.undefCallError(ScriptRuntime.java:3698)
      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getPropFunctionAndThisHelper(ScriptRuntime.java:2221)
      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2214)
      at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:3143)
      at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:2487)
      at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:164)
      at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:398)
      at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:267)
      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3065)
      at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:162)
      at com.gargoylesoftware.htmlunit.javascript.host.EventHandler.call(EventHandler.java:82)
      at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:492)
      at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$6.doRun(JavaScriptEngine.java:457)
      at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:528)
      ... 58 more
      Enclosed exception:
      net.sourceforge.htmlunit.corejs.javascript.EcmaError: TypeError: Cannot call method "onclick" of null
      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3654)
      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3632)
      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3660)
      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3679)
      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.undefCallError(ScriptRuntime.java:3698)
      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getPropFunctionAndThisHelper(ScriptRuntime.java:2221)
      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getPropFunctionAndThis(ScriptRuntime.java:2214)
      at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:3143)
      at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:2487)
      at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:164)
      at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:398)
      at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:267)
      at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3065)
      at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:162)
      at com.gargoylesoftware.htmlunit.javascript.host.EventHandler.call(EventHandler.java:82)
      at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:492)
      at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$6.doRun(JavaScriptEngine.java:457)
      at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:528)
      at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:515)
      at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:507)
      at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:464)
      at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:992)
      at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeEventHandler(EventListenersContainer.java:164)
      at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:177)
      at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:574)
      at com.gargoylesoftware.htmlunit.html.HtmlElement$2.run(HtmlElement.java:936)
      at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:515)
      at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:507)
      at com.gargoylesoftware.htmlunit.html.HtmlElement.fireEvent(HtmlElement.java:941)
      at com.gargoylesoftware.htmlunit.html.HtmlElement.fireEvent(HtmlElement.java:916)
      at com.gargoylesoftware.htmlunit.html.HtmlInput.executeOnChangeHandlerIfAppropriate(HtmlInput.java:468)
      at com.gargoylesoftware.htmlunit.html.HtmlSelect.setSelectedAttribute(HtmlSelect.java:298)
      at com.gargoylesoftware.htmlunit.html.HtmlSelect.setSelectedAttribute(HtmlSelect.java:271)
      at com.gargoylesoftware.htmlunit.html.HtmlOption.setSelected(HtmlOption.java:84)
      at com.gargoylesoftware.htmlunit.html.HtmlOption.doClickAction(HtmlOption.java:219)
      at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1329)
      at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1288)
      at com.gargoylesoftware.htmlunit.html.HtmlElement.click(HtmlElement.java:1257)
      at com.endersys.surgate.SurgateTestCase.click(SurgateTestCase.java:119)
      at com.endersys.common.AntiVirusModuleTest.testSetAntiVirus(AntiVirusModuleTest.java:72)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at junit.framework.TestCase.runTest(TestCase.java:154)
      at junit.framework.TestCase.runBare(TestCase.java:127)
      at org.apache.cactus.internal.AbstractCactusTestCase.runBareServer(AbstractCactusTestCase.java:153)
      at org.apache.cactus.internal.server.AbstractWebTestCaller.doTest(AbstractWebTestCaller.java:119)
      at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody0(AbstractWebTestController.java:93)
      at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody1$advice(AbstractWebTestController.java:224)
      at org.apache.cactus.internal.server.AbstractWebTestController.handleRequest(AbstractWebTestController.java)
      at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody2(ServletTestRedirector.java:101)
      at org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody3$advice(ServletTestRedirector.java:224)
      at org.apache.cactus.server.ServletTestRedirector.doPost(ServletTestRedirector.java)
      at org.jboss.jsfunit.framework.JSFUnitServletRedirector.doPost(JSFUnitServletRedirector.java:46)
      at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody0(ServletTestRedirector.java:72)
      at org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody1$advice(ServletTestRedirector.java:224)
      at org.apache.cactus.server.ServletTestRedirector.doGet(ServletTestRedirector.java)
      at org.jboss.jsfunit.framework.JSFUnitServletRedirector.doGet(JSFUnitServletRedirector.java:52)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.jboss.jsfunit.framework.JSFUnitFilter.doFilter(JSFUnitFilter.java:116)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
      at java.lang.Thread.run(Thread.java:619)
      == CALLING JAVASCRIPT ==
      function () {
      [native code, arity=0]
      }

      ======= EXCEPTION END ========



      I appreciate your help.
      Thanks...