Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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 = '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,
Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (11)
As of 2014-12-25 10:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (160 votes), past polls