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

I'm trying to use WWW::Mechanize's select() method.

The form is being selected OK, and the select menu code looks like this:

<select name="filter1" class="mttextinput"> <option value="" selected></option> <option value="Login Name">Login Name</option> <option value="Subject">Subject</option> <option value="Post">Post</option> </select>

And I'm telling WWW::Mechanize to

$mech->select('filter1', 'Post') || die "$!";

and it dies. With nothing in $!, or in @messages, which it seems to suggest should contain the error message.

Am I missing something? Using the select method correctly? I've been staring at this so long and I'm stumped. Any ideas, anyone?



($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss')
=~y~b-v~a-z~s; print

Replies are listed 'Best First'.
Re: WWW::Mechanize select() method fails
by Cody Pendant (Prior) on Nov 01, 2004 at 04:42 UTC
    Ureka: I tested the select() method on another SELECT tag in the same form, and it worked.

    But not with the example above.

    The difference? That blank first option:

    <option value="" selected></option>

    For some reason, Mechanize, or possibly HTML::Form, doesn't like it.

    Luckily, Mechanize has an HTML-fixing option:

    my $html = $mech->content; $html =~ s[<option value=""( selected)?></option>][]isg; $mech->update_html( $html );
    And now, with that workaround, everything's fine.

    My question now is, who do I tell about this bug?



    ($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss')
    =~y~b-v~a-z~s; print

      The standard way of telling people about bugs would be the CPAN ticket tracker, but you can also email the report to RT, as detailed in the gasp documentation.

      Of course, as always, a short test/program together with the input data and the expectations, preferably using Test::More greatly improves the chance of the bug getting fixed as soon as possible :-)

      Update: As I look on CPAN, petdance has just released WWW::Mechanize 1.05_03, which seems to make the select method return a true value in all cases. If that fixes your bug I don't know, but you might want to test against the current developer release before submitting the bug.

        Thanks for that -- yet another question arising, how do I get CPAN to install that one, rather than what it thinks is the current "up to date" release?


        ($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss')
        =~y~b-v~a-z~s; print
      I think the problem might be that it was returning the value of that option, which is false.
Re: WWW::Mechanize select() method fails
by perrin (Chancellor) on Nov 01, 2004 at 04:33 UTC
    I don't see anything in the documentation or tests to indicate that this method would return a true value when it works, although that's usually a safe assumption. Maybe you should check for yourself if it set the select:
    warn "filter1 is " . $mech->current_form()->param('filter1');
Re: WWW::Mechanize select() method fails
by WhiteBird (Hermit) on Nov 01, 2004 at 03:06 UTC
    What version of WWW::Mechanize are you using? I have an older version and as far as I could discover the select does not work on drop down option groups. Documentation that I could find seemed to indicate that the newest version may be able to handle option groups, but I haven't upgraded my version yet so I can't verify that.
      I've got version 1.04 -- but what do you mean "option groups"? The HTML in my example isn't an option group, it's just a normal select menu. Isn't it?


      ($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss')
      =~y~b-v~a-z~s; print
        Sorry for not being clear. By option groups, I mean the drop-down-arrow box you see on forms. You click on the arrow and a list opens up for the user to select one of several options. I never could get WWW::Mechanize to recognize that type of selection. There's some documentation out there, but I don't have it at my fingertips. I'll see if I can locate it.
      For the record, I've just installed the latest version, 1.05_02 but I'm having the same problem.


      ($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss')
      =~y~b-v~a-z~s; print