views:

103

answers:

1

With Perl's WWW::Mechanize module, I want to select a random value from a select box. How can I do this? With dump_forms I can dump select box values, but how can I get them in an array?

+3  A: 

WWW::Mechanize uses HTML::Form for processing forms. You can get the HTML::Form object with the form_name or form_number methods. So, use something like this:

my $form = $mech->form_number(1);
my $select = $form->find_input('name_of_select_box');
my @values = $select->possible_values;
$select->value($values[int rand @values]); # Choose a possible value at random
cjm