RE: mech and javascript modifying form post action
"Neville Aga" <[email protected]>
| Newsgroups | gmane.comp.lang.perl.modules.lwp |
|---|---|
| Message-ID | <[email protected]> |
Thanks!! That is just what I was looking for. I used your 2nd implementation (large stone hammer with update_html ) as that seemed more intuitive to me. I'd suggest to anyone wanting to work javascript code actions into mech to use this method. It worked like a charm. Cheers, Neville -----Original Message----- From: Eamon Daly [mailto:[email protected]] Sent: Wed 11/8/2006 10:08 AM To: Neville Aga; [email protected] Subject: Re: mech and javascript modifying form post action Each form is represented as an HTML::Form object, so you could manipulate the form directly using those methods: my $form = $mech->form_number(2); $form->action(URI->new_abs('somewhere_else.aspx?appended_stuff', $mech->uri)); $mech->submit_button(form_number => 2); The action method requires a full URI, so that's what the "URI->new_abs" part provides. Otherwise, you could apply the large stone hammer approach of rewriting the HTML yourself using the update_html method: my $html = $mech->content; $html =~ s{\Qaction="start.aspx"} {action="somewhere_else.aspx?appended_stuff"}; $mech->update_html($html); $mech->submit_button(form_number => 2); ____________________________________________________________ Eamon Daly ----- Original Message ----- From: "Neville Aga" <[email protected]> To: <[email protected]> Sent: Tuesday, November 07, 2006 9:36 PM Subject: mech and javascript modifying form post action I am using mech to fill out a form. The problem is javascript is used to alter the form before it is submitted. That is the html of the form initially has <form method=post action=start.aspx>. When the user clicks, javascript alters the form before submission to be <form method=post action=somewhere_else.aspx?appended_stuff>. Since mech does not understand javascript I cant simply click() or submit(). So, how do I fill out the form in mech and then change the target before I use click() or submit? I can use standard perl to get somewhere_else and appended_stuff, so that's not the problem. The problem is that I don't know how to change mechs understanding of the form before submission. Any ideas? Thanks, Neville