Quantcast

Submit form with javascript/AJAX

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Submit form with javascript/AJAX

Andreas Toresäter
Hello all!
First let me say thank you for sharing this very good piece of software. I had a form that I wanted to submit progammatically. Since it was https/ssl I could not use my normal way of looking at the manual made response and then imitating it. (at least I dont know how to see https packets as clear text when connection to a webpage) The answer to this was to use htmlunit, it worked great.

I have now encountered a problem that I cant seem to solve with hmtmlunit or anything else.. I am once again trying to submit a form. When you submit the form manually there are some dhtml that creates a confirmation popup. So you are basically submitting two forms on the same page. Both forms uses OnClick to submit. I have tried htmlunit in this way:

HtmlForm form = confirmPage.getFormByName("addOrder");

   HtmlButtonInput submitButton = form.getInputByName("j_id143")
  
   try {
HtmlPage pageRet = submitButton.click();
} catch (IOException e) {
e.printStackTrace();
}

and the second confirm form:

HtmlForm confirmForm = confirmPage.getFormByName("j_id152");
HtmlButtonInput confirmButton = confirmForm.getInputByName("j_id152:j_id154");
try {
System.out.println("EventB="+confirmButton.fireEvent("click"));
confirmPage = confirmButton.click();
System.out.println("CONFIRM 3:" + confirmPage.asXml());
} catch (IOException e) {
e.printStackTrace();
}

But it does not work, all I get is the same page as I had before I clicked the buttons.

This is how the 2nd  form looks like:

<form id="j_id152" name="j_id152" method="post" action="/mini/mitt_konto/kop_och_salj/kop_och_salj_aktie.html" enctype="application/x-www-form-urlencoded">
                    <input type="hidden" name="j_id152" value="j_id152"/>
                    <div align="center">
                      <input class="knapp" id="j_id152:j_id154" name="j_id152:j_id154" onclick="jQuery('#order_bekrafta').jqmHide();;A4J.AJAX.Submit('_viewRoot','j_id152',event,{'parameters':{'j_id152:j_id154':'j_id152:j_id154'} ,'actionUrl':'/mini/mitt_konto/kop_och_salj/kop_och_salj_aktie.html'} );return false;" value="Bekräfta" type="button"/>
                      
  
                      <input class="knapp" id="j_id152:j_id156" name="j_id152:j_id156" onclick="jQuery('#order_bekrafta').jqmHide();;A4J.AJAX.Submit('_viewRoot','j_id152',event,{'parameters':{'j_id152:j_id156':'j_id152:j_id156'} ,'actionUrl':'/mini/mitt_konto/kop_och_salj/kop_och_salj_aktie.html'} );return false;" value="Avbryt / Ändra" type="button"/>
                    </div>
                    <input type="hidden" name="javax.faces.ViewState" id="javax.faces.ViewState" value="j_id4"/>
                  </form>


Does anyone have an ide why it does not seem to work? Can it have something to do with AJAX? I have tried to set Browserversion to different types, the current is IE8.
I do get a bunch of warnings when retriving the form web page: VARNING: Obsolete content type encountered: 'text/javascript'.
2011-maj-02 14:50:10 com.gargoylesoftware.htmlunit.IncorrectnessListenerImpl notify

------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network
management toolset available today.  Delivers lowest initial
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
Htmlunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/htmlunit-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Submit form with javascript/AJAX

Ronald Brill
On Mon, 2 May 2011 15:09:37 +0200 Andreas Tores?ter wrote:
>
> Since it was https/ssl I
>could not use my normal way of looking at the manual made response and then
>imitating it. (at least I dont know how to see https packets as clear text
>when connection to a webpage)
>

You can try http://www.charlesproxy.com/.


    RBRi
    --------------------------
    Wetator
    Smart web application testing
    http://www.wetator.org



------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network
management toolset available today.  Delivers lowest initial
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
Htmlunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/htmlunit-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Submit form with javascript/AJAX

Andreas Toresäter
Thank you very much Roland!  Very nice piece of software and im sure it can help me to get it working.

/Andreas

On Mon, May 2, 2011 at 6:42 PM, Ronald Brill <[hidden email]> wrote:
On Mon, 2 May 2011 15:09:37 +0200 Andreas Tores?ter wrote:
>
> Since it was https/ssl I
>could not use my normal way of looking at the manual made response and then
>imitating it. (at least I dont know how to see https packets as clear text
>when connection to a webpage)
>

You can try http://www.charlesproxy.com/.


   RBRi
   --------------------------
   Wetator
   Smart web application testing
   http://www.wetator.org



------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network
management toolset available today.  Delivers lowest initial
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
Htmlunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/htmlunit-user


------------------------------------------------------------------------------
WhatsUp Gold - Download Free Network Management Software
The most intuitive, comprehensive, and cost-effective network
management toolset available today.  Delivers lowest initial
acquisition cost and overall TCO of any competing solution.
http://p.sf.net/sfu/whatsupgold-sd
_______________________________________________
Htmlunit-user mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/htmlunit-user
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Submit form with javascript/AJAX

jplistero
Hi Andreas,

did you solve this ?
I am struggeling with the same issue.

best
Loading...