Thanks Corion!
So here it is:
#!/usr/bin/perl -w
use strict;
use Data::Dumper;
use WWW::Mechanize::Firefox;
my $mech = WWW::Mechanize::Firefox->new(
launch => '/usr/bin/firefox',
tab=>'current',
frames => 1,
);
$mech->get('http://www.example.com');
# wait for JS to render the login button
my $retries = 10;
#by xpath
while ($retries-- and ! $mech->is_visible( {xpath => '//*[@id="login"]
+' } )) {
sleep 1;
};
die "Timeout while waiting for site to appear" if 0 > $retries;
print "waitiing retries = $retries\n";
#type the uid & pw
$mech->field( username => 'username'); #by name
$mech->field( password => 'password'); #by name
#sync cos hangs here otherwise
$mech->click( {id=>'login', synchronize => 0}); #by id here
my $string;
my @elements = $mech->xpath('xpath/selector/to/secret/question'); #by
+xpath here
for(my $x=0;$x<=$#elements;$x++){
$string = $elements[$x]->{innerHTML}; #get the string
print "secret question is elements[$x] = $string\n"; #in case ther
+e are multiple matches
}
#ok you need some regex here to decide which question is being asked a
+nd reply with corresponding answer
$mech->field( SecQuestion => 'secret answer'); #by name here
$mech->click( {id=>"confirm", synchronize => 0});
There seemed to be issues about the match of the secret question array having multiple responses.
You asked for many elements but seem to only want a single item.
Did you forget to pass the 'single' option with a true value?
Pass 'all => 1' to suppress this message and receive the count of item
+s.
I think it was trouble shooting lines of code I had added that put me in the wrong iframe... or something.
Thanks for the hints, they really helped!
z