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

Hello All, I need help! I'm totally confused.
I'm trying to access and list the forms available on a page using WWW::Mechanize::Firefox
It is not behaving as I expected.

use strict; use warnings; use diagnostics; use Data::Dumper; use WWW::Mechanize::Firefox; my $mech = WWW::Mechanize::Firefox->new( #env_proxy => 1, #keep_alive => 1, #timeout => 30, #autocheck => 1, autoclose => 1, js_JSON => 'native' ); $mech->get("http://www.w3schools.com/html/html_forms.asp"); my $index; my @forms = $mech->forms(); my $form_obj ; while ( ($index, $form_obj) = each @forms) { print "$index : ", $form_obj , "\n"; #print Dumper ($form_obj), "\n"; } exit;

The $form_obj that is returned is a MozRepl::RemoteObject::Instance.
When I do a print Dumper on it, i can't see anything remotely useful. Everything appears to be describing the connection to Firefox, and i can't see anything to do with a form.
What I'm trying to do is print a list of forms available on a page and then allow the user to select the form in order to input some data.
I've tried googling for some examples of forms with Mechanize::Firefox and MozRepl::RemoteOjects but what i found was neither clear nor well explained. Any assistance would be greatly appreciated!

Replies are listed 'Best First'.
Re: Completely Confused with Mechanize::Firefox Forms
by daxim (Curate) on Jul 12, 2013 at 17:15 UTC
    use HTML::Form qw(); for my $form ($mech->forms) { print Dumper(HTML::Form->parse($form->{outerHTML}, $mech->uri)); }

      Ok that's great, thank you very much BUT now I'm a bit more confused!
      This is the blurb from the Mechanize::Firefox documentation

      " $mech->current_form() print $mech->current_form->{name}; Returns the current form. This method is incompatible with WWW::Mechanize. It returns the DOM <form> object and not a HTML::Form instance."

      Thank you nonetheless! Is there 'proper' way to do this ?? Or is the documentation wrong / inaccurate !

        Hi there. I'm not clear on what you want exactly. You just want the names of the forms? WWW::Mechanize has a dump_forms method- so you may not need Mechanize::Firefox. Also, If you use the firefox 'firebug' extension, you can inspect any html element and then use the name or value in the script to mechanize what you want to do..
      forns returns HTML::Form objects, so they're already HTML::Form objects, why reparse?
        bahm, firefox doesn't return HTML::Form objects