http://www.perlmonks.org?node_id=575581


in reply to Re: Ticking multiple checkboxes with WWW::Mechanize / WWW::Mechanize::Shell
in thread Ticking multiple checkboxes with WWW::Mechanize / WWW::Mechanize::Shell

YES! it helps!

You are the most wonderful big hot scaley thing that eats people, sets haystacks on fire and swoops away with sheep EVER!

I am sort of short-cutting on using Ethereal by using the LiveHTTPHeaders in Firefox (which Corion pointed me to earlier this year)

It gives you similar output in terms of what your web browser is sending, but I agree, Ethereal is a great tool!

What I did:

I installed HTTP::Recorder using perl -MCPAN -e shell on Cygwin on my workstation...

The install asked for HTTP::Request::Params

which asked for:

Email::MIME::Modifier
Email::MIME::ContentType
Class::Accessor::Fast

Email::MIME::Modifier asked for:

Email::MIME
Email::MIME::Encodings
Email::MIME::ContentType
Email::MessageID
Email::Simple

Email::MIME asked for:

Email::MIME::Encodings
Email::MIME::ContentType
Email::Simple
MIME::Types

Email::MessageID asked for:

Email::Address

BOY what a lot of modules! but they all installed with only a few warnings and no errors thank goodness so that was OK...

I copied the code from the example in leira's article "Web Testing with HTTP::Recorder" that you suggested, then found I needed needed to install HTTP::Proxy as well...

I did that, cranked it up and got this error:

$ ./record.pl Cannot initialize proxy daemon: Address already in use at /usr/lib/per +l5/site_perl/5.8/HTTP/Proxy.pm line 271.

had a look at HTTP::Proxy] and added:

$proxy->port( 3128 ); # the classical accessors are here!
right after:
my $proxy = HTTP::Proxy->new;

Started it up and was away...

I am using Opera because this horrible web interface won't even work in Firefox which cares more about "irelevant" things like having <tr> and </tr> around the <td>...</td>s in your tables and other pernickity things like that...) (HTML coding standards? what are THEY?)

In my web browser I set my HTTP proxy to localhost Port 3128 ...

I checked "Use proxy for local servers" (because I found it didn't want to talk to my proxy without that),

opened a new tab in Opera and browsed to http://http-recorder/

(yes, it is literally that - I first wondered if it meant "put the name of the box you're running the script on" but of course you've already specified that in your proxy settings and HTTP::Recorder just needs to see you ask for http://http-recorder/ in the browser to know to show you its output page...)

Then back in the first window I reloaded my troublesome URL...

Well, it let me load the page fine, but when I filled out and submitted the form it came back with "An unknown error has occurred." from the web page, and the perl script's output on screen said:

Use of uninitialized value in substitution (s///) at /usr/lib/perl5/si +te_perl/5.8/HTTP/Recorder/Logger.pm line 171. Use of uninitialized value in concatenation (.) or string at /usr/lib/ +perl5/site_perl/5.8/HTTP/Recorder/Logger.pm line 173. Use of uninitialized value in substitution (s///) at /usr/lib/perl5/si +te_perl/5.8/HTTP/Recorder/Logger.pm line 171. Use of uninitialized value in concatenation (.) or string at /usr/lib/ +perl5/site_perl/5.8/HTTP/Recorder/Logger.pm line 173. Use of uninitialized value in substitution (s///) at /usr/lib/perl5/si +te_perl/5.8/HTTP/Recorder/Logger.pm line 171. Use of uninitialized value in concatenation (.) or string at /usr/lib/ +perl5/site_perl/5.8/HTTP/Recorder/Logger.pm line 173. Use of uninitialized value in substitution (s///) at /usr/lib/perl5/si +te_perl/5.8/HTTP/Recorder/Logger.pm line 171. Use of uninitialized value in concatenation (.) or string at /usr/lib/ +perl5/site_perl/5.8/HTTP/Recorder/Logger.pm line 173. Can't locate object method "query_param" via package "(lots of stuff c +ut out) ... &time1=12%3A09&dayOfWeek=SUN&dayOfWeek=TUE=&save=Save" (p +erhaps you forgot to load "(lots of stuff cut out) ... &time1=12%3A09 +&dayOfWeek=SUN&dayOfWeek=TUE&save=Save"?) at /usr/lib/perl5/site_perl +/5.8/HTTP/Recorder.pm line 347.

WAAAAH! :'-O :'-((( .oO(Oh no!) I thought... .oO(Back to square one!)

I hit refresh in the window to http://http-recorder/ to see what it had... and it had a lot...

(there are lots of fields jammed onto this page, as you can probably imagine!)

I thought .oO(Well, it didn't work in updating the page, but it's worth trying the perl source it generated anyway)

I just kept the very most relevent bits and put them in a sample script...

#!/usr/bin/perl use warnings; use strict; use WWW::Mechanize; use WWW::Mechanize::FormFiller; my $agent = WWW::Mechanize->new( autocheck => 1 ); my $formfiller = WWW::Mechanize::FormFiller->new(); $agent->get('http://server/page_with_form/'); $agent->form_name('manageDaemonForm'); $agent->tick('reportLogEnabled', 'on'); $agent->tick('dayOfWeek', 'TUE'); $agent->tick('dayOfWeek', 'SUN'); $agent->field('option', '1'); $agent->field('time1', '12:09'); $agent->tick('appendToReportLog', 'on'); $agent->click('save');

I saved it, ran it and held my breath...

$ ./update_report_logging.pl There are 4 forms named manageDaemonForm. The first one was used. at +./update_report_logging.pl line 14

FOUR!!!??? you have to be KIDDING me!!! NOOO!!! it's going to try and put the data in some random field and corrupt the database AGAIN!

Oh well... I'll check the web interface in Opera to see what it's done...

\o/ YAY \o/ !!! It WORKED!!!

Thank you, thank you, thank you! I've been bashing my head on this all week, now it's Friday night, and I can go home, have a weekend, and stop thinking about it, not having to spend my own time on the weekend hacking around trying to find an answer!

/me hugs planetscape