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

Hey i need some help again with mechanize :( I will try to explain this the best way i can... I came upon a form with 2 buttons on it however i cant get mechanize to click_button() because for some reason it wont find the input values and names. So i checked the sites source and it goes something like this

<form name="aspnetForm" method="post" action=".... <div> <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="...ran +dom letters <br> <table cellpadding="10" cellspacing="10"> ... the table <input type="submit" name="... and the name of the button
so what do i need to do here in order to get mechanize to see that button, im thinking its something about that hidden viewstate thing.

Replies are listed 'Best First'.
Re: Mechanize hidden fields
by perrin (Chancellor) on Apr 14, 2007 at 04:45 UTC
    Mech won't change hidden fields. This is what I do to get around it:
    foreach my $form ($mech->forms()) { map { $_->readonly(0) } $form->inputs(); }
Re: Mechanize hidden fields
by friedo (Prior) on Apr 14, 2007 at 04:24 UTC
    The hidden field shouldn't matter. What do you mean when you say mechanize doesn't see the button? What is your code, and what error are you getting?
      im sorry i posted the question like an ass without reading about the __viewstate thing.. the code is simple
      $mech->click_button(name => 'ctl00$Main$Send_Button');
      the error is
      No clickable input with name ctl00$Main$Send_Button at /usr/lib/perl5/ +site_perl/5.8.8/WWW/Mechanize.pm line 1461
      ive read about the postback and what i know so far is that i have to get the value of the __viewstate, __eventvalidation, select the Main send button value and submit the form however i dont know how to get the value of __eventstate which would be something like this
      value="/wEPDwUKMTg1MjcyMzgzMw9kFgJmD2QWAgIBD2QWAgIBD2QWAgIGD2QWAmYPFgI +eA2FsdAURUG93ZXJlZCBieSBHb29nbGVkGAEFFWN0bDAwJE1haW4kTXVsdGlWaWV3MQ8P +ZGZk" />
      from what ive read it should be $vs =~ and then the pattern match which i dont know how to do
        $mech->click_button(name => 'ctl00$Main$Send_Button');

        Is the name of the submit button literally 'ctl00$Main$Send_Button' ? Or are $Main and $Send_Button variables? Variables do not interpolate inside single quotes.

        ive read about the postback and what i know so far is that i have to get the value of the __viewstate, __eventvalidation, select the Main send button value and submit the form however i dont know how to get the value of __eventstate which would be something like this
        Again, Mechanize shouldn't change the values of form fields that are there already. If you need to extract the values of existing form fields, use my $viewstate = $mech->value( '__VIEWSTATE' );