#!/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 there are multiple matches } #ok you need some regex here to decide which question is being asked and reply with corresponding answer $mech->field( SecQuestion => 'secret answer'); #by name here $mech->click( {id=>"confirm", synchronize => 0});