Jump to content

How to handle optional windows in Autoit?


Recommended Posts

I am automating a software installation in Windows7 using AutoIt.

During the installation, in between if a error window appears. I want to click ENTER.

If the error window not appears then I should NOT do anything. Simply its should go to the next section.

I have tried "WinActive and WinWaitActive" But its waiting for the window to appear. If window not appears its not going to the next screen.

Any idea how to handle this situation?

Link to comment
Share on other sites

WinWait and WinWaitActive have a timeout parameter, so if the window doesn't appear within a certain time, the function stops waiting.

 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

  • Moderators

You could do something like this, depending on how long it would take for the optional window to come up:

For $i = 1 To 10
            If WinExists("Error Installing", "Wrong Credentials") Then
                ControlClick("Error Installing", "Wrong Credentials", "Button1")
                ExitLoop
            Else
                Sleep(500)
            EndIf
        Next

The bigger question would be what exactly is causing the optional window (what scenario) so you can program a series of checks and balances. Also, does the software support silent installation, so you don't have to mess with automating the GUI at all?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Its the hardest part to automate unexpected windows as you do not know if they come around and for how long. For example unexpected browser chats or advertisements overlay or suddenly credentials invalid. 

For more or less known popups with only ok button i just grab the text and put it in log as a warning and click ok automatically. If ok and cancel button i do the same in the assumption ok is most logical. 

If winexists('*') is a little.tricky but could work if your windows are having a certain regexclass.and use then a regex to match.

Link to comment
Share on other sites

and an example to filter on a regular expression assuming you know the unexpected windows and the expected window. When either of them is found it should continue otherwise wait for timeout

Example()

Func Example()
    ; Retrieve a list of window handles.
    ;Assume max times is 10 times 
    for $x=1 to 10
        Local $hTimer = TimerInit() ; Begin the timer and store the handle in a variable.
        Local $aList = WinList("(Error Installing)|(expected windowtitle)")
        Local $fDiff = TimerDiff($hTimer) ; Find the difference in time from the previous call of TimerInit. The variable we stored the TimerInit handlem is passed as the "handle" to TimerDiff.

        consolewrite($fDiff & " - windows found:" & $aList[0][0] & @CRLF)

        ; Loop through the array displaying only visable windows with a title. And jump out
        if $aList[0][0] > 0 Then
            For $i = 1 To $aList[0][0]
                If $aList[$i][0] <> "" And BitAND(WinGetState($aList[$i][1]), 2) Then
                    consolewrite("Title: " & $aList[$i][0] & @CRLF & "Handle: " & $aList[$i][1])
                EndIf
            Next
            ExitLoop
        EndIf
        
    
        ;sleep 1 second
        sleep(1000)
    Next
    
EndFunc   ;==>Example

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...