Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

mykl's scratchpad

by mykl (Monk)
on Mar 24, 2010 at 13:18 UTC ( #830555=scratchpad: print w/replies, xml ) Need Help??

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 = ''; 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...' ];
Log In?

What's my password?
Create A New User
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2018-04-26 02:07 GMT
Find Nodes?
    Voting Booth?