ajose has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I need to auto submit a form which has javascript in it. The html is given below.
<form action="/goform/formHandlerConfigureDMPName" method="post" onsub +mit = "return validateDMPNameOnSubmit(this)"> <td width="5%"><img src="../invis.gif" alt="" width="50" heigh +t="30"/></td> <td width="45%">DMP Name:</td> <td width="50%"><input type="text" name="DMPName" value="Curre +nt Name" maxlength="129"/>&nbsp;&nbsp;<input type="submit" value="App +ly"/></td> </form>
The output of mech-dump utility is:
POST http://xxx.xxx.xxx.xxx/goform/formHandlerConfigureDMPName DMPName=Current Name (text) <NONAME>=Apply (submit)
But while trying to set the current form to the desired one using the method form_with_fields(), it returns an error "No elements found for form with fields [DMPName]".
my $input_name = 'DMPName'; my $web_url = 'http://xxx.xxx.xxx.xxx/DMP_config.asp'; my $mech = WWW::Mechanize::Firefox->new(); $mech->get($web_url, no_cache => 1); $current_form = $mech->form_with_fields($input_name); print "Present value of $input_name: " . $mech->value($input_name);
With the above code snippet it is possible to select and set the current form to different forms in the same web page.

Any help to figure out this issue is appreciated.

Replies are listed 'Best First'.
Re: Not able to select the form with WWW::Mechanize::Firefox using form_with_fields()
by Anonymous Monk on Jun 28, 2011 at 09:44 UTC
    Works for me, prints

    Present value of DMPName: Current Name[0]

      Thanks for the reply.

      The code works for another form in the same web page which has multiple inputs and options. But unfortunately I could not figure out the reason for which the same code does not work for the above mentioned form. Hence please let me know for any other work around for this issue by avoiding the function form_with_fields().

        Hence please let me know for any other work around for this issue by avoiding the function form_with_fields().

        If you don't want to use form_with_fields, then you can use any other form... function, your choice