0

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?

brian d foy
  • 129,424
  • 31
  • 207
  • 592
Jazz
  • 5,747
  • 5
  • 43
  • 55

1 Answers1

4

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
  • 61,471
  • 9
  • 126
  • 175