From: shankar_perl_rookie on
Hello All,

I am looking to automate IE search using Perl. The site I am trying to
access has a security certificate and I am trying to send an enter
command to just click 'OK' on the security dialog box that opens. I
tried win32::IEAutomation in combination with win32::winclicker which
probably has the exact method to do this but somehow in my case, it is
not able to recognize the dialog box i feel. Here is the code I have.
Please take a look and let me know where I am possibly going wrong:

use strict;
use Win32::OLE;
use Win32::OLE::Const 'Microsoft Excel';
use Win32::IEAutomation;
use Win32::IEAutomation::WinClicker; # this will provide methods to
interact with dialog box
#use Win32::GuiTest; # qw(FindWindowLike GetWindowText
SetForegroundWindow SendKeys);

my $title ='Choose a digital certificate';
my $wait= 5;

# Creating new instance of Internet Explorer

my $ie = Win32::IEAutomation->new( visible => 1);

# Site navigation

$ie->gotoURL('https:......');

# managing security dialog boxes

my $clicker = Win32::IEAutomation::WinClicker->new();
$clicker->push_confirm_button_ok($title,$wait);
$ie->WaitforDone; # we will wait here for complete loading of
navigated site

The push confirm method is as follows :

sub push_confirm_button_ok{

print "hello inside yes loop \n";
my ($self, $title,$wait) = @_;
print "$self \n$title \n$wait \n";
$wait = 5 unless $wait;
$self->{autoit}->WinTitleMatchMode(3);
my $window = $self->{autoit}->WinWait($title, "", $wait);
if ($window){
print "break 4 inside open window loop \n";
$self->{autoit}->WinActivate($title);
$self->{autoit}->Send('{ENTER}');
}else{
print "WARNING: No Security Alert dialog is present. Function
push_security_alert_yes is timed out.\n" if $warn;
}
}


It is never entering the break point 4 which means that $window is not
recognized. What could be the reason ?

Thanks a lot
From: Mark on
On Jul 1, 8:48 am, shankar_perl_rookie <mulshan...(a)gmail.com> wrote:
> Hello All,
>
> I am looking to automate IE search using Perl. The site I am trying to
> access has a security certificate and I am trying to send an enter
> command to just click 'OK' on the security dialog box that opens. I
> tried win32::IEAutomation in combination with win32::winclicker which
> probably has the exact method to do this but somehow in my case, it is
> not able to recognize the dialog box i feel. Here is the code I have.
> Please take a look and let me know where I am possibly going wrong:
>
>  use strict;
>  use Win32::OLE;
>  use Win32::OLE::Const 'Microsoft Excel';
>   use Win32::IEAutomation;
>  use Win32::IEAutomation::WinClicker; # this will provide methods to
> interact with dialog box
>  #use Win32::GuiTest; # qw(FindWindowLike GetWindowText
> SetForegroundWindow SendKeys);
>
>  my $title ='Choose a digital certificate';
>  my $wait= 5;
>
>  # Creating new instance of Internet Explorer
>
> my $ie = Win32::IEAutomation->new( visible => 1);
>
> # Site navigation
>
>   $ie->gotoURL('https:......');
>
> # managing security dialog boxes
>
>    my $clicker = Win32::IEAutomation::WinClicker->new();
>    $clicker->push_confirm_button_ok($title,$wait);
>    $ie->WaitforDone; # we will wait here for complete loading of
> navigated site
>
> The push confirm method is as follows :
>
> sub push_confirm_button_ok{
>
>         print "hello inside yes loop \n";
>         my ($self, $title,$wait) = @_;
>         print "$self \n$title \n$wait \n";
>         $wait = 5 unless $wait;
>         $self->{autoit}->WinTitleMatchMode(3);
>         my $window = $self->{autoit}->WinWait($title, "", $wait);
>         if ($window){
>                 print "break 4 inside open window loop \n";
>                 $self->{autoit}->WinActivate($title);
>                 $self->{autoit}->Send('{ENTER}');
>         }else{
>                 print "WARNING: No Security Alert dialog is present. Function
> push_security_alert_yes is timed out.\n" if $warn;
>         }
>
> }
>
> It is never entering the break point 4 which means that $window is not
> recognized. What could be the reason ?
>
> Thanks a lot

I've never used those modules. You might try using Win32::GuiTest to
send ENTER to that dialog:

use Win32::GuiTest qw(SendKeys SetForegroundWindow WaitWindow);

my $whdl = WaitWindow($title,$wait) || die "Window '$title' not found.
\n";
SetForegroundWindow($whdl) || die "could not set foreround window
'$title'";
SendKeys('{ENTER}');