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

Dear monks, I am new in Perl and Mechanize. I want to read an Html page and follow the link. This page has a table with radio buttons, in a browser you tick one, and then click on an "Ok" button to see the chosen information.

The source page in html is as follow (printed using  print $mech->content() :

<tbody> <tr class="moduloTableauCouleur"> <td> <input type=radio name="%%RBGROUP16843009" value="wt_200 +0-selector[1]" ></td> </td> <td>0001887609&nbsp;</td> <td>&nbsp;</td> <td>010249X02&nbsp;</td> <td>Verif. código barra&nbsp;</td> <td align="right">52,00 &nbsp;</td> <td>ZRCB&nbsp;</td> <td>&nbsp;</td> </tr> <tr class="moduloTableauBlanc"> <td> <input type=radio name="%%RBGROUP16843009" value="wt_200 +0-selector[2]" ></td> </td> <td>0001891413&nbsp;</td> <td>&nbsp;</td> <td>010249X02&nbsp;</td> <td>Verif. código barra&nbsp;</td> <td align="right">52,00 &nbsp;</td> <td>ZRCB&nbsp;</td> <td>&nbsp;</td> </tr> <tr class="moduloTableauCouleur"> <td> <input type=radio name="%%RBGROUP16843009" value="wt_200 +0-selector[3]" ></td> </td> <td>0001891414&nbsp;</td> <td>&nbsp;</td> <td>010249X02&nbsp;</td> <td>Verif. código barra&nbsp;</td> <td align="right">30,00 &nbsp;</td> <td>ZRCB&nbsp;</td> <td>&nbsp;</td> </tr> </tbody>

I would like to select one of these radio buttons but I haven't succeeded. I have tried different ways:

$mech->tick( name => 'wt_2000-selector[3]', value => 'Select'); $mech->select( name => '%%RBGROUP16843009', value => 'wt_2000-selector +[3]'); $mech->submit_form( form_name=>'%%RBGROUP16843009',fields=>'wt_2000-se +lector[3]', button => 'Select');
but none has worked. Does anybody know how to do it? Thanks in advance. Yours faithfully, Josep Bonet

Replies are listed 'Best First'.
Re: Select radio button
by Anonymous Monk on May 24, 2011 at 10:24 UTC

      Thank you!

      I have followed your indications and I have found in  http://search.cpan.org/~gaas/HTML-Form-6.00/lib/HTML/Form.pm that buttons have always the same name. After this enlightenment, I have read  http://www.perlmonks.org/?node_id=547270 and I have found the solution.

      I only need to write:

       $mech->set_fields('%%RBGROUP16843009'=>'wt_2000-selector[3]');

      Thanks again.