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

Perl Lords,

I am hitting this mechanize bug: http://code.google.com/p/www-mechanize/issues/detail?id=25

Basically, mechanize does not store _empty_ hidden fields. What this means is, that I can not set those fields. I wanted to know if anyone know of any workarounds (or fixes) to this bug?

Basically, using mechanize I need to click a link that does this:
javascript:__doPostBack('x','y')

But, mechanize does not support javascript. So I have to hardcode the javascript actions. On that page, __doPostBack sets __EVENTTARGET and __EVENTARGUMENT. However, since __EVENTTARGET and __EVENTARGUMENT are defined as hidden _empty_ fields, I can not set them and so I can not replicate the behavior of __doPostBack using mechanize.

Note that mechanize does seem to store hidden _non-empty_ fields.

Any pointers will be appreciated.

tia, rouble

Replies are listed 'Best First'.
Re: mechanize bug - is there a workaround?
by almut (Canon) on Mar 14, 2008 at 20:30 UTC

    Which version are you using? I just tried the sample snippet given in the bugreport you linked to, and it seems to work fine now with the current version (WM-1.34 and libwww-5.805), i.e. I can set the empty hidden fields without any problem (and $mech->current_form->dump displays them)...

      ~$ perl -MWWW::Mechanize -e 'print "$WWW::Mechanize::VERSION\n"' 1.34 ~$ perl -version This is perl, v5.8.8 built for i486-linux-gnu-thread-multi
      How do I tell my version of libwww-perl?

      I used $mech->current_form->dump and I can see __VIEWSTATE, which is a non empty hidden field. But, I do not see __EVENTTARGET or __EVENTARGUMENT which are empty hidden fields.

      I wonder what I am doing different from you.

      tia, rouble
        How do I tell my version of libwww-perl?

        Check the version of the module LWP

        $ perl -MLWP -e 'print "$LWP::VERSION\n"' 5.805

        and, just to be sure, also check HTML::Form (part of the bundle), as I suspect the problem could have originated in that module (Update: this doesn't make much sense, though — as the revision control timestamp of the respective file dates back to 2005/12/07 :).  Mine shows 1.0.54.

        I wonder what I am doing different from you.

        No idea :)  Here's what I did:

        use WWW::Mechanize; my $mech = WWW::Mechanize->new(); my $url = "file:///.../test.html"; # the mentioned form $mech->get($url); $mech->current_form->dump(); $mech->set_fields( '__EVENTTARGET' => 'mynewvalue' ); $mech->current_form->dump();

        which gives:

        $ ./674272.pl POST .../Browse.aspx?MyToken=632797078501515540 [aspnetForm] __EVENTTARGET= (hidden readonly) __EVENTARGUMENT= (hidden readonly) __VIEWSTATE=/wEPDwUJ (hidden readonly) POST .../Browse.aspx?MyToken=632797078501515540 [aspnetForm] __EVENTTARGET=mynewvalue (hidden readonly) __EVENTARGUMENT= (hidden readonly) __VIEWSTATE=/wEPDwUJ (hidden readonly)
Re: mechanize bug - is there a workaround?
by EvanCarroll (Chaplain) on Aug 21, 2008 at 20:25 UTC