Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Clicking on Confirmation Button (JS) using WWW::Mechanize::Firefox

by edimusrex (Monk)
on Feb 15, 2017 at 18:22 UTC ( #1182086=perlquestion: print w/replies, xml ) Need Help??

edimusrex has asked for the wisdom of the Perl Monks concerning the following question:

I have run into a situation where I need to click on a js confirmation popup which running WWW::Mechanize::Firefox. I have read through the documentation and I didn't see anything that allows me to do so (I may have missed it). If any one knows a way to get past this it would be greatly appreciated. Here is the code thus far.

#!/usr/bin/perl use warnings; use strict; use WWW::Mechanize::Firefox; use Data::Dumper; my $url = '<my_url>'; my $username = '<username>'; my $password = '<password>'; my $mech = WWW::Mechanize::Firefox->new('ssl_opts'=> {'SSL_verify_mode +'=>0 }, autocheck => 0); $mech->autoclose_tab( 0 ); $mech->get($url); $mech->field(USERNAME => $username); $mech->field(PASSWORD => $password); $mech->click({ xpath => '//*[@id="loginButton"]' }); $mech->click({xpath => '//a[@onclick="changeTab(\'View Auto Attendants +\', \'TelephonyControls\', \'ViewAutoAttendants\');return(false);"]' +}); ### Fails here, obviously because confirmation_is is not a part of the + Mechanize::Firefox module but part of selenium. Would like to use M +echanize if at all possible. $mech->confirmation_is("Click OK to View Auto Attendants, if you have +not saved your work, click Cancel and be sure to save it");
  • Comment on Clicking on Confirmation Button (JS) using WWW::Mechanize::Firefox
  • Download Code

Replies are listed 'Best First'.
Re: Clicking on Confirmation Button (JS) using WWW::Mechanize::Firefox
by Anonymous Monk on Feb 16, 2017 at 03:55 UTC
      it's a javascript popup confirm box

        What do you mean by "javascript popup confirm box"?

        Is it the kind of dialog box like the one opened by a call to the Javascript/browser alert() function or is it some HTML that asks for confirmation?

        If it is a call to alert(), then the easiest approach is to replace that confirmation button with a Javascript function that returns the result you want:

        $mech->evaluate_in_page(<<'JS'); window.alert = function(msg) { return true }; JS

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1182086]
Approved by stevieb
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (2)
As of 2021-09-19 00:03 GMT
Find Nodes?
    Voting Booth?

    No recent polls found