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

Hello. On website there are two radio's with the same name but with different id.
<input id="sexM" type="radio" value="M" name="Sex"> <input id="sexF" type="radio" value="F" name="Sex">
So when i try select "Sex" with value "M"
$mech->field('Sex' => 'M')
i got error:
2 elements found for input with name 'Sex' at xxx.pl
I tried set_fields, field, some xpath and nothing :( There is someone who can help me?

Regards.

Replies are listed 'Best First'.
Re: WWW::Mechanize::FireFox - radios with the same name
by Corion (Patriarch) on Feb 06, 2012 at 12:21 UTC

    It seems that radio boxes are not really supported. I suggest retrieving the element(s) by the ID and then ->clicking on them. Alternatively, use ->field() with the id instead of the name, as documented in $mech->field().

      Could you tell me more about this getting element by ID? When I'm trying clicking this radio i got message that it's not a button :( . Corion help me! I see you got skill in it. Sorry for my English - I don't use translators and I'm from Poland .

        The documentation for ->field() in WWW::Mechanize::Firefox says:

        A selector prefixed with '#' must match the id attribute of the input. A selector prefixed with '.' matches the class attribute. A selector prefixed with '^' or with no prefix matches the name attribute.

        I'm not sure how to make this clearer, but maybe an example helps:

        $mech->field('#foo', 'bar'); # set value of element with id "foo" to " +bar"

        I don't think that radio boxes are well-supported with WWW::Mechanize::Firefox though, because I've never needed them.

        A reply falls below the community's threshold of quality. You may see it by logging in.