Wednesday, 8 October 2014

Test 14: Print values of form fields, update them and print new values

Test:
Get values of all fields of a form, update the values and then print new values

Learning: 
$form->value used to get values


Solution:

use strict;
use warnings;

use WWW::Mechanize;

my $m = WWW::Mechanize->new();
$m->get("http://vienna.yapceurope.org/ye2007/search");

my $count = 1;
for my $form ($m->forms) 
{
    print "form $count fields are:\n";
    $count++;
    for ($form->param) 
{
        printf "%s - %s\n", $_, $form->value($_);
    }
    print "\n";
}

$m->submit_form(
    form_number => 1,
    fields    => { name  => 'honey', town => 'Delhi', country =>

'india', pm_group => 'Cam.pm'},
);

$count = 1;
print "After filling data to form\n";
for my $form ($m->forms) 
{
    print "form $count fields are:\n";
    $count++;
    for ($form->param)
{
        printf "%s - %s\n", $_, $form->value($_);
    }
    print "\n";
}


output snapshot:

No comments:

Post a Comment