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

I need to access a web based select list box using the perl module mechanize. The html is:
<tr><td bgcolor="#ABABAB" align="center"><b>Rename a Folder</b></td> </tr> <tr> <td bgcolor="#DCDCDC" align="center"> <form action="folders_rename_getname.php" method="post"> <tt><select name="old"> <option value="">[ Select a folder ]</option> <option value="Evaluation-Folder">Evaluation-Folder</option> <option value="Evaluation-Folder/Evaluation-Sub-Folder-1">Evaluation-F +older/Evaluation-Sub-Folder-1</option> </select></tt> <input type="submit" value="Rename" /> </form></td></tr> <tr><td bgcolor="#FFFFFF" align="left">&nbsp;</td> </tr>
The code:
$n = 'old'; $mech->select( $n, "Evaluation-Folder/Evaluation-Sub-Folder-1",1); $mech->submit('Delete');
The error response:
Input "old" not found at Web_Mail_Evaluation_suite.pl line 596 Can't call method "value" on an undefined value at /Library/Perl/5.8.6 +/WWW/Mechanize.pm line 1137.
Any ideas of what i could do to access a selection?

Respectully yours, Thelma Vance, thelma1944@netzero.com

Replies are listed 'Best First'.
Re: mechanize accessing a listbox
by jettero (Monsignor) on Dec 13, 2006 at 17:42 UTC
    I'm no expert, but based on the docs, it looks like you want something more like this:
    $mech->submit_form( form_number => 1, fields => { old => 'Evaluation-Folder/Evaluation-Sub-Folder-1' +, }, button => 'Delete' );

    It appears to be telling you there's no select called old to be found...

    EDIT: I tried WWW::Mechanize on one of my own sites that I'm developing and all I can say is: thanks dude. This module rocks and I had never heard of it... Just wow. (Also, my code above appears to work as written.)

      Thanks for the hint. Big help! While trying the above i get an error of: Can't call method "value" on an undefined value at /Library/Perl/5.8.6/WWW/Mechanize.pm line 1137. Any ideas what this may be? Looking at the Mechanize.pm code: my $form = $self->{form}; if ($number > 1) { $form->find_input($name, undef, $number)->value($value); } else { if ( ref($value) eq 'ARRAY' ) { $form->param($name, $value); } else { $form->value($name => $value); } } } Respecfully yours, Thelma Vance, thelma1944@netzero.com
        [editorial note: please use the <code> tags...]

        ...looks like Mechanize is calling value() on an undefined value. At a guess, you apparently didn't get the site: $mech->get($url). You have to get() before you can start interacting with it.

        -Paul