in reply to Re^5: Not able to select the form with WWW::Mechanize::Firefox using form_with_fields()
in thread Not able to select the form with WWW::Mechanize::Firefox using form_with_fields()

There are 4 forms in the web page. When trying to select the first form, it shows that there are 4 elements with form number 1. Also when trying to select forms 2, 3 or 4, it gives error.

This issue might be because of poorly written webpage. Since I have no control over this, I cannot select this form.

But while using WWW::Mechanize, I am able to select any forms with the form number. Also I am able to do successful submission. Since some other forms use java script, I am not using this module. I just wanted to avoid clutter by using both modules in the same script.

  • Comment on Re^6: Not able to select the form with WWW::Mechanize::Firefox using form_with_fields()

Replies are listed 'Best First'.
Re^7: Not able to select the form with WWW::Mechanize::Firefox using form_with_fields()
by Anonymous Monk on Jun 28, 2011 at 14:10 UTC

    When trying to select the first form, it shows that there are 4 elements with form number 1.

    Before you quoted "Current form:4 elements found for form number 1"., this is not an error message

    Also when trying to select forms 2, 3 or 4, it gives error.

    What error?

      When trying to select form with form_number 2, the error message is "No elements found for form number 2".

      Both these error messages including "4 elements found for form number 1" leads to quit the program based on the value of the parameter autodie which is set to 1 by default.

      Even if I turned off autodie, the value function does not return the present value when the error is "4 elements found for form number 1". Please see below for the code snippet and output for the same:

      my $input_name = 'DMPName'; my $web_url = 'http://xxx.xxx.xx.xx/config.asp'; my $mech = WWW::Mechanize::Firefox->new(activate => 0, autoclose => 1, autodie =>0); $mech->get($web_url, no_cache => 1); $current_form = $mech->form_number(1); print "Present value of $input_name: " . $mech->value($input_name) . " +\n";
      Output:
      4 elements found for form number 1 at ..... No elements found for input with name 'DMPName' at .... Present value of DMPName:
      But interestingly while selected the form 10 which is not existing, I got following output:
      $current_form = $mech->form_number(10);
      No elements found for form number 10 at ... Present value of DMPName: Current Name

        As another way of debugging what form gets selected via ->form_number, you can print its HTML content:

        print $mech->current_form->{innerHTML};

        Maybe there is a bug in how the current form gets set up, but without seeing the exact HTML you're talking about (or better, a 10 line example that reproduces the same problem), it's hard to diagnose.