Jump to content

Waiting for a control to become active


 Share

Recommended Posts

Hi everyone!

I'm new to this forum, but I've already wrote a few basic scripts with AutoIt. I need to automate a process (obviously :oops: ) where there could be popup error windows. I have many data files to handle and I already take care of the "no error" case with a for... loop. In other words, I do a ShellExecute on a file with a specific extension, it opens the right program (and the file). It's embedded in a loop that goes through a lot of sub-folders with similar files and treats them one at a time.

After the ShellExecute, the program window opens and I "AutoIt"-click on the Process button. Another window opens which displays the progress of data processing. There is an Ok button on this last window, but it's not enabled until the end of processing. The process time is not constant, so I got roughly around it with a Sleep statement. During the processing, there could be a popup window with an error message about some wrong data (the title is always the same for these error windows). It's not predictable and it stops processing until the Ok button is clicked on this window.

My question is this: is there a way to instruct the script to wait while the Ok button is enabled and at the same time "scanning" the available windows on the Desktop for error window? I saw some functions related to GUI (one you create yourself), but what about "third party" windows? I was thinking of using a while... loop, but I don't know how to scan for the error window without burdening the CPU more nor how to check the state of a button.

Suggestions? Thanks!

Link to comment
Share on other sites

  • Moderators

Hi, Zut, welcome to the forum :oops: For something like this, check out WinWaitActive and WinClose in the help file. You would basically:

WinWaitActive ( "title of the error window")

And then:

WinClose ( "title of the window")

If you are unsure of the window's title, check out the AutoIt Window Info tool (Au3Info.exe) inside the directory where you installed AutoIT. Hope this helps. Let us know if you encounter any roadblocks.

Edited by JLogan3o13

"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

WinWaitActive is NOT the way to go.

You are checking for something which might exist or not - in that case you need to use WinExists. If the error window exists then do whatever you need to do in case of error, if there is no error then continue the way you want.

If you are waiting for an error to pop up (WinWaitActive) and there is no error, your script will be stuck, waiting forever for a window to pop-up in order to continue execution.

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Link to comment
Share on other sites

  • Moderators

You are quite correct, enaiman. I misread the OP, thought he said he was getting the error every time. You could look at AdLibRegister to check for the pop up instead, Zut.

"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

I found how to do it!

Here's a snippet of my script :

AdlibRegister("PopupReviewException")
While ProcessedSetsOK() <> 1
WEnd
AdlibUnRegister("PopupReviewException")


Func PopupReviewException()
  If WinExists("Review Exception") Then
    ControlClick("Review Exception", "OK", "Button1", "left")
    WinWaitClose("Review Exception")
  EndIf
EndFunc

Func ProcessedSetsOK()
  If ControlCommand ("Processed Sets", "OK", "Button1", "IsEnabled") Then
    ControlClick("Processed Sets", "OK", "Button1", "left")
    WinWaitClose("Processed Sets")
    Return 1
  EndIf
  Return 0
EndFunc
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...