【问题标题】:How to handle optional windows in Autoit?如何处理 Autoit 中的可选窗口?
【发布时间】:2016-01-25 15:06:28
【问题描述】:
我正在使用 AutoIt 在 Windows7 中自动安装软件。
在安装过程中,如果出现错误窗口。我想点击 ENTER。
如果没有出现错误窗口,那么我不应该做任何事情。只是它应该转到下一部分。
我尝试过“WinActive 和 WinWaitActive”,但它正在等待窗口出现。如果没有出现窗口,则不会进入下一个屏幕。
知道如何处理这种情况吗?
【问题讨论】:
标签:
windows
automation
automated-tests
ui-automation
autoit
【解决方案1】:
做一个while循环:
$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
【解决方案2】:
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')