Skip Menu | You are currently an anonymous guest. | Login | Return to Main | About rt.cpan.org
 

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.

X Report information
Id: 6898
Status: resolved
Left: 0 min
Priority: 0/0
Queue: WWW-Mechanize

Owner: Nobody
Requestors: magnus [...] huckvale.net
Cc:
AdminCc:

Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



X History Display mode: Brief headersFull headers
#   Sun Jul 13 11:01:28 2003 guest - Ticket 2940: Ticket created  
Subject: Forms with options using javascript
[text/plain 1.2k]
I have a little problem with some pages with forms using javascript to put options.
As WWW::Mechanize is not yet interpreting javascript, options that should be filled by some javascript code don't get set.

Here is the HTML that makes WWW::Mechanize fail.
<select name=month >
<option value="">Select Month</option>
</select>

If I do this:
$agent->field('month', '2');
I get an error:
Uncaught exception from user code:
Illegal value '2' at WWW-Mechanize-0.52/lib/WWW/Mechanize.pm line 409
HTML::Form::ListInput::value('HTML::Form::ListInput=HASH(0x881a1c8)',2) called at /usr/share/perl5/HTML/Form.pm line 333
HTML::Form::value('HTML::Form=HASH(0x883effc)','month',2) called at WWW-Mechanize-0.52/lib/WWW/Mechanize.pm line 409
WWW::Mechanize::field('WWW::Mechanize=HASH(0x86130a0)','month',2) called at myscript.pl line 74


I have to type this code instead:
my %a =
( 'value' => '2',
'name' => 'month' );
$agent->{form}->push_input("option", \%a); # fucking javascript
$agent->{form}->value('month' => '2');

Is there an easier way? Or something in WWW::Mechanize or HTML::Form should be fixed so the first method works even if the options are not in HTML?

By the way, I love WWW::Mechanize.

#   Thu Jul 08 14:08:27 2004 magnus[...]huckvale.net - Ticket created  
From: "Magnus" <magnus[...]huckvale.net>
To: <bug-www-mechanize[...]rt.cpan.org>
Subject: Overriding Form Select/Option values
Date: Thu, 8 Jul 2004 18:53:01 +0100
[text/plain 3.1k]

As discussed, I think it would be handy to be able to pre-process HTML
before submitting a form via WWW::Mechanize.

In this case, I wanted to submit an Option to a Select input that was
not in the original HTML.

Cheers,

Magnus



18:38 <Magnus> do you use HSBC internet banking?
18:38 <Andy> No sir.
18:39 <Magnus> well, I'm automating the downloading of statements
18:39 <Andy> ok
18:39 <Magnus> and the first thing it shows you is a <SELECT>
18:39 <Magnus> but it only shows a year of statements at a time
18:39 <Magnus> each option is a different month
18:39 <Magnus> so it'd be nice to submit the form for months that aren't
on that particular page
18:39 <Magnus> I'll just change my algorithm
18:39 <Andy> huh.
18:39 <Magnus> but it'd definitely be good to be able to override
18:39 <Andy> It's more than a Mech issue.
18:40 <Magnus> oh ok
18:40 <Andy> I believe that HTML::Form won't let you do it.
18:40 <Magnus> the parser behind it?
18:40 <Magnus> fair enough
18:40 <Andy> It's HTML::Form that squawks.
18:40 <Magnus> Illegal value '2004-07-01' for field 'statementDate' at
/usr/local/perl580/lib/site_perl/5.8.0/WWW/Mechanize.pm line 474
18:40 <Magnus> it's no biggy
18:40 <Andy> What version of Mech you on?
18:41 <Magnus> 0.74
18:41 <Magnus> just what happeend to be here, iirc
18:42 <Andy> Just wanna see what line 474 is.
18:42 <Andy> Yup,, it's HTML::Form that is complaining.
18:43 <Magnus> ah well
18:43 <Magnus> I could probably reconstruct the form
18:43 <Andy> It's funny how Mech has put all this new stress on
HTML::Form.
18:43 <Magnus> but I'll just have it iterate through the pages
18:43 <Andy> You could ALSO....
18:44 <Andy> wait, let me see if I added this yet.
18:45 <Andy> Write a subclass of mech
18:45 <Andy> that overrides the _parse_html() method
18:45 <Magnus> oh goodness
18:45 <Magnus> not for this project :)
18:45 <Magnus> it's nearly finished
18:45 <Magnus> thanks though
18:45 <Andy> that modifies $self->{content} and then calls
SUPER::_parse_html()
18:45 <Andy> no no, hold on. It's simple.
18:45 <Andy> That's ALL it has to override.
18:46 <Andy> and it modifies that before the parsing.
18:46 <Magnus> oh... interesting
18:46 <Andy> so it's doing your form tweaking on the fly, instead of you
doing it statically.
18:46 <Magnus> yeah
18:46 <Magnus> I get the idea
18:46 <Magnus> I've half written my iterating functino now though :)
18:46 <Andy> Maybe I need a page_preprocess method or something.
18:47 <Andy> so you could then call
18:47 <Andy> my $mech = WWW::Mechanize->new( preprocess =>
\&magnus_function_that_sticks_last_years_statements_in_the_select );
18:47 <Andy> Because I get the feeling that many people are in your
boat.
18:48 <Magnus> it seems like something thing people might want to do
18:49 <Andy> Starting with you.
18:49 <Andy> Do me a favor, if you would pleaes.
18:49 <Andy> Send a quick little email describging your situation to
bug-www-mechanize[...]rt.cpan.org
18:49 <Magnus> sure
18:49 <Andy> so that I don't lose track of it.
18:49 <Magnus> I'll do it now
18:49 <Andy> I haven't looked at Mech in a while, so maube it's time.
18:49 <Andy> heck, you could cut&paste this IRC log. :-)
18:50 <Andy> ok, I'm off to lunch. Thanks.
18:50 <Magnus> ok
18:50 <Magnus> heh, I'm having dinner...



#   Sun Aug 29 10:04:31 2004 guest - Ticket 2940: Correspondence added  
[text/plain 584b]
[guest - Sun Jul 13 11:01:28 2003]:

> I have a little problem with some pages with forms using javascript to
> put options.
> As WWW::Mechanize is not yet interpreting javascript, options that
> should be filled by some javascript code don't get set.

I've encountered a similar problem on a JavaScript form that creates checkboxes. I wish there was a way to force setting fields without checking to see whether they really exist on the form. Maybe add a 'ignore' parameter to $mech->field that doesn't check to see whether the $name value exists, so this error doesn't get thrown?
#   Wed Oct 20 23:27:13 2004 MARKSTOS - Subject changed from 'Overriding Form Select/Option values' to 'wish: ability to submit values that HTML::Form doesn't allow.'  
#   Wed Oct 20 23:27:14 2004 MARKSTOS - Severity Wishlist added  
#   Sat Aug 19 07:47:15 2006 MARKSTOS - Correspondence added  
[text/plain 264b]
This request is resolved by the arrival of HTML::Form::ForceValue:
http://search.cpan.org/dist/HTML-Form-ForceValue

See also this related bug report in the HTML::Form queue:
http://rt.cpan.org/Ticket/Display.html?id=8327

This ticket can be resolved.

Mark


#   Sat Aug 19 07:47:16 2006 RT_System - Status changed from 'new' to 'open'  
#   Sat Aug 19 08:41:06 2006 PETDANCE - Status changed from 'open' to 'resolved'