As a part of my automation test, I have to right click on a folder and select one of the option using Perl in Windows10.
Go to 'C:\MyProject\', Right-Click on 'logs' present there and select 'Pin to Start' (as an example).
I have followed some of the examples mentioned here - https://www.perl.com/pub/2005/08/11/win32guitest.html/ and here - https://metacpan.org/pod/Win32::GuiTest::Examples. I tried it to do using Win32::GuiTest.
I am able to open the explorer with the directory, select the folder and do right click. However, I am unable to select the option after right click.
use strict;
use warnings;
use Data::Dumper;
use Win32::GuiTest qw(:ALL);
$Win32::GuiTest::debug = 0;
sub bring_window_to_front {
my $window = shift;
my $success = 1;
if ( SetActiveWindow($window) ) {
print "* Successfully set the window id: $window active\n";
}
else {
print "* Could not set the window id: $window active\n";
$success = 0;
}
if ( SetForegroundWindow($window) ) {
print "* Window id: $window brought to foreground\n";
}
else {
print "* Window id: $window could not be brought to foreground\n";
$success = 0;
}
return $success;
}
my $explorer_path = "%windir%/explorer.exe";
my $folder_path = "C:\\MyProject";
# Open the location
system ($explorer_path, $folder_path);
sleep 2;
my @whnds = FindWindowLike( undef, "^MyProject", "" );
if( !@whnds ){
die "Cannot find window with title/caption MyProject\n";
}
else{
printf( "Window handle of MyProject is %x\n", $whnds[ 0 ] );
}
sleep 2;
# select the logs directory
SendKeys("logs");
# Send the right click button
SendKeys("{APP}");
sleep 2;
#### Till here everything is working fine
#### I am able to do right click, but unable to select any option. Hitting a road block here
#### Tried these but no result
# MouseClick('Pin to Start');
# MenuSelect('Pin to Start');
# PushChildButton($whnds[ 0 ],"Pin to Start");
One thing I am still wondering, whether I am going in right direction. Am I using the right module or this work is for some other modules(Win32::GUI or Win32::OLE ?).