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

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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2015-08-31 08:52 GMT
Find Nodes?
    Voting Booth?

    The oldest computer book still on my shelves (or on my digital media) is ...

    Results (354 votes), past polls