I'm trying to automate the clicking of a button on a web page form, but a javascript confirm() is being called onsubmit. Is there any way to override the confirm() function?
Web page contains:
function cFact()
{
return confirm("Do you really want to restore factory settings?\nAll c
+urrent settings will be lost.")
}
...
<form action="defaults.cgi" class="StandardForm" method="get" name="fa
+cotry" onsubmit="return cFact();">
use WWW::Mechanize::FireFox;
use Data::Dumper;
use strict;
use warnings;
my $ipaddr = '192.168.0.72';
my $mech = WWW::Mechanize::FireFox->new();
$mech->get('http://' . $ipaddr . '/advanced.html');
my @confirm_text;
$mech->eval_in_page('confirm("Testing...");',
{ confirm => sub { push @confirm_text, @_; return 1; } }
);
#~ print "building tree:\n";
#~ binmode STDOUT;
#~ $mech->tree;
print "about to click button:\n";
binmode STDOUT;
$mech->click('facotry');
print "clicked, sleeping...\n";
binmode STDOUT;
sleep 5;
print Dumper(\@confirm_text);
binmode STDOUT;
sleep 60; # prevent the tab from being closed for a while
The output I get is:
about to click button:
clicked, sleeping...
$VAR1 = [
'Testing...'
];
Oddly,