Mech and hidden fields

mpeters on 2006-06-15T19:04:23

I was writing some controller tests for an application that makes heavy use of Javascript and it bit me again that WWW::Mechanize does not allow you to set the values of hidden fields, since HTML::Form considers them read-only.

This has always bugged since if Mech is going to be useful for testing it's almost required that you mess with hidden fields because sometimes your JS will do it, or you want to make sure you've protected yourself against elementary hacking attempts.

Anyway, I always forget how to work around this, so I'm putting it here to always remind myself. If you have a hidden input named 'rm', this is how you would make it settable for Mech:

    my $form = $mech->form_name('my_form');
    $form->find_input('rm')->readonly(0);
    $mech->set_fields(rm => 'foo');


suggestion: put it on annocpan

thinc on 2006-06-16T00:16:47

if you put it on annocpan, it might get included in the docs where everyone can feel the love:

http://www.annocpan.org/dist/WWW-Mechanize-1.18/lib/WWW/Mechanize.pm

Re:suggestion: put it on annocpan

mpeters on 2006-06-16T14:46:46

Excellent idea and it has been added - http://www.annocpan.org/user/PETDANCE/WWW-Mechanize-1.18/lib/WWW/Mechanize.pm#221

Mech is a little weak in general

Alias on 2006-06-16T04:44:16

I've found Mech to be fairly innocent in a number of different ways.

In the end, I wrote my own web automation layer that is capable of running under "combat conditions" (broken HTML, crazy evil anti-scraping techniques, sites that change the page layout regularly etc).

Re:Mech is a little weak in general

pemungkah on 2006-06-17T00:12:14

Have you released it? I'm definitely interested.

Thanks

pemungkah on 2006-06-17T00:11:30

Good info. Thanks.

I'll check AnnoCPAN for others. Would make a nice Util plugin for WWW::Mechanize::Pluggable.