我正在使用AutoIt在Windows7中自动安装软件。
在安装过程中,如果出现错误窗口。我想点击ENTER。
如果没有出现错误窗口,那么我不应该做任何事情。它应该转到下一节。
我尝试过“WinActive和WinWaitActive”,但它等待窗口出现。如果窗口没有出现,则不会进入下一个屏幕。
知道如何处理这种情况吗?
做一会儿循环:
$w = 0
While($w = 0)
If(WinActive("ERROR WINDOW"))Then
Send("{ENTER}")
$w = 1
ElseIf(ControlGetText("YOUR WINDOW", "", "[CLASS:Static; INSTANCE:2]") <> "SOME TEXT") Then
$w = 1
;and something else
EndIf
Sleep(1000)
WEnd
AdlibRegister()
是正确的选择。从帮助文件:
“...通常用于检查无法预料的错误。例如,您可以在脚本中使用adlib,这会导致错误窗口无法预测地弹出。”
每100毫秒(可调整)调用该函数以检查错误对话框的出现:
Global $sErrorWindow = 'ErrorDialogName'
Global $iDelayHowOftenDoTheFunctionCall = 100
AdlibRegister('_isErrorWindowDisplayed', $iDelayHowOftenDoTheFunctionCall)
Func _isErrorWindowDisplayed()
If WinActive($sErrorWindow) <> 0 Then
WinActivate($sErrorWindow) ; just to be sure that the ENTER command is on the correct window/dialog
; either do
Send('{ENTER}')
; or
ControlClick('title', 'text', 'controlID')
EndIf
EndFunc
; do your software installation processing here
; ...
; ...
; don't forget to unregister the function at the end
AdlibUnRegister('_isErrorWindowDisplayed')