在Windows的文件夹中通过右键单击选择项目

时间:2019-04-08 08:08:46

标签: windows perl win32gui

作为自动化测试的一部分,我必须右键单击一个文件夹,然后在Windows10中使用Perl选择一个选项。

转到“ C:\ MyProject \”,右键单击此处显示的“日志”,然后选择“固定到启动”(作为示例)。

我已遵循此处提到的一些示例-https://www.perl.com/pub/2005/08/11/win32guitest.html/和此处-https://metacpan.org/pod/Win32::GuiTest::Examples。我试过使用Win32 :: GuiTest来做。

我能够使用目录打开资源管理器,选择文件夹并右键单击。 但是,右键单击后我无法选择该选项。

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");

我仍然想知道的一件事,就是我是否朝着正确的方向前进。 我使用的是正确的模块,还是该功能适用​​于其他模块(Win32 :: GUI或Win32 :: OLE?)。

0 个答案:

没有答案