Jump to content
Sign in to follow this  
Zut

Waiting for a control to become active

Recommended Posts

Zut

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!

Share this post


Link to post
Share on other sites
JLogan3o13

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

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
enaiman

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 :)

Share this post


Link to post
Share on other sites
JLogan3o13

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.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
Zut

Thanks for the answers!

AdlibRegister seems to be what I need. :oops:

Any hints about checking when the Ok button becomes active?

Share this post


Link to post
Share on other sites
Zut

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

Share this post


Link to post
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
Sign in to follow this  

×