in reply to Re^4: 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()

The given HTML form does not have a formId or form Name. Hence I cannot use any of those. And with form_number it returned "Current form:4 elements found for form number 1". Hence I am really blocked due to this issue.

I don't understand how you are blocked. How is form_number not working for you?

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

Replies are listed 'Best First'.
Re^6: Not able to select the form with WWW::Mechanize::Firefox using form_with_fields()
by ajose (Acolyte) on Jun 28, 2011 at 13:56 UTC
    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.

      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