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

Hi , I had written a code to integrate Mechanize module in my program. ...... ......... $agent->click('Button'); after this statement , it will load a html page containing five buttons having same name and different values. In that i would like to click on the 4th button... how can i do that? I wrote like this, but its failed (Getting server error...)
### Previous form submission $agent->click('Button'); #### End my $form = $agent->current_form; my $update = $form->find_input('FormButton','view',4); my $request = $update->click($form); $agent->{req} = $request; $agent->_do_request;
This is not working.... ----------------------------- This is my html code having more buttons with same name..
<html> <head> <title>Account</title> </head> <body bgcolor="#FFFFFF" text="#000000"> <form method="POST" action="abc.asp"> <div align="center"><center><table border="1" width="600" cellspacin +g="0" cellpadding="0"> <tr> <td width="100%"><table border="0" width="100%" cellspacing="0" +cellpadding="0"> <tr> <td width="100%" bgcolor="#000080"><font face="MS Sans Serif +" color="#FFFFFF"><small><strong>&nbsp; Account</strong></small></font></td> </tr> <tr> <td width="100%" bgcolor="#C0C0C0"><table border="0" width=" +100%" cellspacing="0" cellpadding="0"> <tr> <td width="57%"><font face="MS Sans Serif">&nbsp; <input + type="submit" value="Find" name="FormButton" style="font-family: MS Sans Serif">&nb +sp; <input type="text" name="SearchAccount" size="17" style="font-family: MS Sa +ns Serif"></font></td> <td width="43%"><div align="right"><p><font face="MS San +s Serif">&nbsp; <input type="submit" value="Apply" name="FormButton" style="fon +t-family: MS Sans Serif"> <input type="submit" value="Save" name="FormButton" style="font +-family: MS Sans Serif"> <input type="submit" value="View" name="FormButton" style="font +-family: MS Sans Serif"> <input type="submit" value="Close" name="FormButton" style="fon +t-family: MS Sans Serif">&nbsp;&nbsp; </font> </div> </td> </tr> </table> </td> </tr> <tr align="center"> <td width="100%" bgcolor="#C0C0C0"><table border="0" width=" +100%" cellspacing="0" cellpadding="0"> <tr> <td width="28%"><font face="MS Sans Serif">&nbsp; Sales +Reps</font></td> <td width="15%"><font face="MS Sans Serif"><input type=" +text" name="Sales_Rep" size="9" style="font-family: MS Sans Serif" value=""></font></td> <td width="15%"><font face="MS Sans Serif"><input type=" +text" name="Sales_Rep2" size="8" style="font-family: MS Sans Serif" value=""></font></td> <td width="17%"><font face="MS Sans Serif"><input type=" +text" name="Sales_Rep3" size="8" style="font-family: MS Sans Serif" value=""></font></td> </tr> </table> </td> </tr> </table> </td> </tr> </table> </div> </form> </body> </html>
Please post a solution. Regards

Replies are listed 'Best First'.
Re: How can i recognize a button having same name
by adrianh (Chancellor) on Jul 07, 2003 at 11:15 UTC
      adrianh, Is there any solution? If you have any idea, pls post a comment here. Regards,

        There's a hack to get around it listed in the bug report I referenced. There is no "nice" way of doing it unfortunately.

        I just switched to not having multiple buttons with the same name. Getting easier testing with W::M was worth the (minor) effort.

Re: How can i recognize a button having same name
by revdiablo (Prior) on Jul 07, 2003 at 20:49 UTC

    Instead of your version:

    $agent->{req} = $request; $agent->_do_request;

    You might want to try:

    $agent->request($request);

    This seems to be the new internal method instead of _do_request. Apparently it takes in the $request object as a parameter, rather than requiring you to set it manually with $agent->{req}.

    Note: this is completely untested. I just looked at WWW::Mechanize's perldocs and made an educated guess. :)