in reply to WWW::Mechanize on broken HTML
Update: (21-06-2007) Oops, fixed the submit field.<form> <input type="checkbox" name="passenger" value="somevalue" /> <input type="submit" name=".submit" value="OK"> </form>
The following example (tick.pl) demonstrates the checkbox ticking.
And supposed that the form URL is http://localhost/form.html, the program produces the following when run:use strict; use warnings; use WWW::Mechanize; # set some dummy vars my $target_field = 'passenger'; my $target_value = 'somevalue'; # get the URL and check my $url = shift or die "Need URL, pal!\n"; my $mech = WWW::Mechanize->new; $mech->get($url); $mech->success or die $mech->response->status_line, "\n"; # select the form $mech->form_number(1); # check original value my $set_value = $mech->value($target_field); $set_value = 'undef' unless defined $set_value; print "[1] value for $target_field: ($set_value)\n"; # tick the checkbox $mech->tick($target_field, $target_value); $set_value = $mech->value($target_field); $set_value = 'undef' unless defined $set_value; print "[2] value for $target_field: ($set_value)\n";
HTH,$ perl tick.pl http://localhost/form.html [1] value for passenger: (undef) [2] value for passenger: (somevalue)
Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!
|
|---|