[Mechanize-users] How to select randomly named checkbox

Aaron Patterson
Thu, 15 Feb 2007 03:45:12 -0000

On Wed, Feb 14, 2007 at 05:56:34PM -0800, Chris Harris
wrote:
> I am trying to select a checkbox that is randomly named depending on the ID
assigned to it by the webpage.
>
> [9713816764515361h] is the random bit.
>
>     #<WWW::Mechanize::CheckBox:0x7a2b3c0
>      @checked=false,
>
@name="communityContentFields[9713816764515361h].postToArea_checkbox",
>      @value="true">
>
> What code should I use to check the box?

You can find the checkbox with a regex.  For example, if you have a form
object named ''form'':

  form.checkboxes.find { |f|
    f.name =~ /communityContentFields/  # Or a more specific regex
  }.checked = true

--
Aaron Patterson