我正在尝试使用Win32 :: GuiTest来测试基于InstallShield的卸载过程。我可以打开控制面板,找到应用程序,然后调用InstallShield但我没做什么似乎让我在安装程序中选择“删除”按钮。到目前为止,我已经:
sub uninstall($;$) {
my ($name, $force) = @_;
if (! defined($force)) {
$force=0;
}
my @windows;
# Control Panel window
my $cpwin;
my $w;
my $text;
# Install Shield window
my $iswin;
# Run the Control Panel (In windir, do `control appwiz.cpl`)
system("cd %windir% && control appwiz.cpl");
sleep 1;
print("Opened control panel\n");
# Get the Window ID of the control panel
# FIXME - this label is system specifie (W7)
@windows = FindWindowLike(undef, "Programs and Features", "");
$cpwin = $windows[0];
printf("Found CP window ID %x\n", $cpwin);
# Get the Folder View window of the control panel
# Find the list of applications
@windows = FindWindowLike($cpwin, "FolderView");
$w = $windows[0];
# Find program in the list
if (Win32::GuiTest::SelListViewItemText($w, $name) == 0) {
printf("Could not find '$name'.\n");
return -1;
}
# Invoke the installer for by pressing [Return]
Win32::GuiTest::SendKeys("~");
# Wait for the "initializing the wizard" window
@windows = Win32::GuiTest::WaitWindow("InstallShield Wizard", 5);
# Wait for the real installer window
sleep 10;
@windows = Win32::GuiTest::WaitWindow("InstallShield Wizard", 3);
$iswin = $windows[0];
# Win32::GuiTest::WaitWindow("Remove");
printf("Found IS window ID %x\n", $iswin);
# Win32::GuiTest::SetFocus($iswin);
@windows = FindWindowLike($iswin, "&Remove", "Button");
my $remove = $windows[0];
printf("Found remove button %x\n", $remove);
Win32::GuiTest::PushButton($remove);
# Win32::GuiTest::SetFocus($remove);
# Win32::GuiTest::SendKeys("%r");
# Win32::GuiTest::MouseClick("Remove",$iswin);
# Win32::GuiTest::CheckButton($remove);
# Win32::GuiTest::SendKeys("{DOWN}{DOWN}");
# Win32::GuiTest::MouseClick("Next",$iswin);
# Win32::GuiTest::PushChildButton($iswin, "Cancel");
我尝试过的任何事情(最后都没有注释)似乎没有任何效果。
如果有任何重要的话,我在Windows 7上使用ActivePerl和Win32 :: GuiTest。
(善待。我的Perl可能很糟糕。我有25年的编程经验但在Perl不到一个月。)
答案 0 :(得分:0)
我正在尝试驾驶安装程序,这似乎是一个红鲱鱼。在XP上(即使在VM中),这很好用。我怀疑问题是安装程序提供了对话框而Notepad提供了一个窗口,并且在W7中以某种方式处理它们的方式与XP不同。我会回到为什么W7不起作用,但XP是我现在必须做的事情,这就足够了。
答案 1 :(得分:0)
Win32::GuiTest::PushButton
方法将按钮Text或ID作为参数,而不是窗口/控件对象。因此,您根本不需要调用FindwindowLike
方法。
但Win32::GuiTest::PushButton
仅从前景窗口查找按钮,这可能不适用于所有情况。应该使用Win32::GuiTest::PushChildButton
。
请尝试这种方式:
#@windows = FindWindowLike($iswin, "&Remove", "Button");
#my $remove = $windows[0];
#printf("Found remove button %x\n", $remove);
sleep 10;
Win32::GuiTest::PushChildButton($iswin, "&Remove", 50);