httpunit: Issue with Submit button()?

Help
rm95054
2006-10-16
2013-04-26
  • rm95054
    rm95054
    2006-10-16

    My code is as follows:

    <SCRIPT language="javascript">
       function doSubmit() {
           document.form1.action.value = 'submit';
           document.form1.submit();
       }
       function doCancel() {
          location.href="FederationDone.jsp?metaAlias=lip.red.iplanet.com&termStatus=cancel";
       }
    </SCRIPT>

           <form name="form1" method="post" action="http://lip.red.iplanet.com:7001/amserver/federation">
             <tr>            <td colspan="3"> <div align="center">                <input type="hidden" name="RelayState" value="http://lip.red.iplanet.com:7001/amserver/config/federation/default/FederationDone.jsp?metaAlias=lip.red.iplanet.com">

                   <input type="hidden" name="metaAlias" value="lip.red.iplanet.com">
                   <input type="hidden" name="action" >
                   <select name="selectedprovider" size="1" >
                                     <option value="http://sam.red.iplanet.com"> http://sam.red.iplanet.com </option>
                            </select>                             </div></td>
             </tr>
             <tr>

               <td colspan="3">&nbsp;</td>
             </tr>
                    <tr>            <td width="175"><div align="right">                <input name="button" type="button" onClick='doSubmit()' value="submit">
                 </div></td>
               <td width="1">&nbsp;</td>
               <td width="170"><input name="button2" type="button" onClick='doCancel()' value="cancel"></td>
               </tr>
                  </form>

    Now in my code I am doing the following:

               webF = response.getForms();
               webF[0].getButtons()[0].click();
               response = wc.getCurrentPage();
               System.out.println("The title of page is:" + response.getTitle());

    I am able to get both the buttons and the click on cancel button goes fine. But if I try to click on submit button
    I get the following exception:

    org.mozilla.javascript.JavaScriptException: java.util.NoSuchElementException
           at org.mozilla.javascript.JavaScriptException.wrapException(JavaScriptException.java:70)
           at org.mozilla.javascript.FunctionObject.call(FunctionObject.java:418)
           at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2169)
           at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:2163)
           at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:58)
           at com.meterware.httpunit.javascript.JavaScript$JavaScriptEngine.performEvent(JavaScript.java:172)
           at com.meterware.httpunit.scripting.ScriptableDelegate.doEvent(ScriptableDelegate.java:56)
           at com.meterware.httpunit.Button.doOnClickEvent(Button.java:103)
           at com.meterware.httpunit.Button.click(Button.java:81)
           at test.main(test.java:81)
    java.lang.RuntimeException: Event 'doSubmit()' failed: org.mozilla.javascript.JavaScriptException: java.util.NoSuchElementException
           at com.meterware.httpunit.javascript.JavaScript$JavaScriptEngine.handleScriptException(JavaScript.java:199)
           at com.meterware.httpunit.javascript.JavaScript$JavaScriptEngine.performEvent(JavaScript.java:175)
           at com.meterware.httpunit.scripting.ScriptableDelegate.doEvent(ScriptableDelegate.java:56)
           at com.meterware.httpunit.Button.doOnClickEvent(Button.java:103)
           at com.meterware.httpunit.Button.click(Button.java:81)
           at test.main(test.java:81)

    Any help appraciated?
    thx

     
    • dvir
      dvir
      2006-10-17

      Can you try getSubmitButtons istead?
      I face the same few weeks ago and it was solved the problem

       
    • rm95054
      rm95054
      2006-10-17

      I tried that. Basically it seems it can see the button, but when I click on it, it throws an exception.
      Some debug output for the related button:
      SubmitButton[] sb = webF[0].getSubmitButtons();
      System.out.println( "Button 1-" + sb.length);
      System.out.println( "Button 1-" + sb[0].getID());
      System.out.println( "Button 1-" + sb[0].getName());
      System.out.println( "Button 1-" + sb[0].getTitle());
      System.out.println( "Button 1-" + sb[0].getText());
      System.out.println( "Button 1-" + sb[0].getTagName());
      System.out.println( "Button 1-" + sb[0].getType());
      System.out.println( "Button 1-" + sb[0].getValue());
      System.out.println( "Button 1-" + sb[0].toString());
      sb[0].click();

      Button 1-HTTPUNIT-SUPPLIED
      Button 1-submit
      Button 1-
      Button 1-Submit with =
      java.util.NoSuchElementException
              at java.util.StringTokenizer.nextToken(StringTokenizer.java:332)
              at com.meterware.httpunit.HttpUnitUtils.parseContentTypeHeader(HttpUnitUtils.java:51)
              at com.meterware.httpunit.WebResponse.readContentTypeHeader(WebResponse.java:1090)
              at com.meterware.httpunit.WebResponse.getContentType(WebResponse.java:209)
              at com.meterware.httpunit.HttpWebResponse.<init>(HttpWebResponse.java:61)
              at com.meterware.httpunit.HttpWebResponse.<init>(HttpWebResponse.java:67)
              at com.meterware.httpunit.WebConversation.newResponse(WebConversation.java:76)
              at com.meterware.httpunit.WebWindow.getResource(WebWindow.java:164)
              at com.meterware.httpunit.WebWindow.getSubframeResponse(WebWindow.java:128)
              at com.meterware.httpunit.WebWindow.getResponse(WebWindow.java:121)
              at com.meterware.httpunit.WebWindow.sendRequest(WebWindow.java:110)
              at com.meterware.httpunit.WebRequestSource.submitRequest(WebRequestSource.java:253)
              at com.meterware.httpunit.WebRequestSource.submitRequest(WebRequestSource.java:232)
              at com.meterware.httpunit.WebForm.submitRequest(WebForm.java:96)
              at com.meterware.httpunit.WebForm.doFormSubmit(WebForm.java:107)
              at com.meterware.httpunit.SubmitButton.doButtonAction(SubmitButton.java:67)
              at com.meterware.httpunit.Button.click(Button.java:81)
              at test.main(test.java:88)

       
    • tiblu
      tiblu
      2006-11-09

      It may be a long shot, but I got a lot of trouble from FORM-s that did not have ID and NAME attributes. You don't have ID. I think you might go for setting the ID same as the NAME attribute.