You still don't show any Perl code, so I can't comment on how you call your Javascript and how it fails for you.
Personally, I check Javascript validation functions without actually submitting the form:
# Set up values to be tested ... $mech->field( $name => $value ); ... my ($value, $type) = $mech->eval_in_page('validateIpSettings()'); is($value, 'some expected value');
As your Javascript already is structured nicely, this conveniently eliminates the need for overriding window.alert. If you still want to override window.alert, you can do so by passing in the appropriate hash in the $env parameter to ->eval_in_page():
# create myalert as Javascript function my $myalert = $mech->declare(<<JS); function (msg) {}; JS my ($value, $type) = $mech->eval_in_page('validateIpSettings()', { + alert => $myalert });
In reply to Re^3: (OT) How to override the javascript alert when submitting a form using WWW::Mechanize::Firefox
by Corion
in thread (OT) How to override the javascript alert when submitting a form using WWW::Mechanize::Firefox
by ajose
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |