Handling Unexpected Windows
When recording a script, you record the expected behavior of the application or web site. At playback, unexpected situations can occur, like a modal window that displays a message (for example : the file xxx already exists, do you want to replace?).
The script must be able to do an action on this popup window and continue, and if the popup window does not appear, the script just continues.
The ExistW function can be used to set up conditional steps that will be executed only if the specified window exists. The script below with Notepad clicks Yes button in the popup window asking if the file has to be replaced, popup window which appears only if the file to save already exists.
UseWindow("NOTEPAD.EXE|Edit|Untitled - Notepad|1",1)
UseWindow("NOTEPAD.EXE|Notepad|Untitled - Notepad",1)
'If the file already exists, a new window appears and we click Yes button.
If existW("NOTEPAD.EXE|CtrlNotifySink|Confirm Save As")=1 then
UseWindow("NOTEPAD.EXE|CtrlNotifySink|Confirm Save As|7",1)
If you want to do an action when a specific window can pop up at an erratic time during the automation process, use OnAction function.