I have since replaced this article with a newer clean up procedure, here.
A major headache on any automation project is the scenario of a script locking, thus preventing all future scripts from running.
To overcome this much focus should be paid to the Login script, cramming as much clean-up-goodness in there as possible.
The below code is regularly being updated, and is currently in use for cleaning up all dialog errors encountered in IE6 and IE8.
Do Until bBrowsersClosed = true
Do While true
'Allow any PC-side processes to catch-up
wait 2
'Are we able to exit
If Browser("index:=0").Exist(0) = FALSE _
AND fGetDialog().exist(0) = FALSE _
AND Dialog("nativeclass:=#32770", "regexpwndtitle:=Visual Studio Just\-In\-Time Debugger", "index:=0").Exist(0) = FALSE _
AND Window("nativeclass:=EPWindow", "index:=0").Exist(0) = FALSE Then
bBrowsersClosed = true
Exit do
End If
'Iterate through all possible scenarios which require termination
'Remove Dialog > Dialog such as 'Choose File to Upload > Insert Disk' themed pop up
If fGetDialog().Dialog("nativeclass:=#32770", "index:=0").WinButton("text:=Cancel").exist(0) Then
fGetDialog().Dialog("nativeclass:=#32770", "index:=0").WinButton("text:=Cancel").click
Exit Do
End If
'Remove Dialog > Dialog such as 'Choose File to Upload > Path Does Not Exist' themed pop up
If fGetDialog().Dialog("nativeclass:=#32770", "index:=0").WinButton("text:=OK").exist(0) Then
fGetDialog().Dialog("nativeclass:=#32770", "index:=0").WinButton("text:=OK").click
Exit Do
End If
'Handle 'OK' dialog appearing on the screen
If fGetDialogButton("OK").exist(0) Then
fGetDialogButton("OK").click
Exit Do
End If
'Handle 'Close' dialog appearing on the screen
If fGetDialogButton("Close").exist(0) Then
fGetDialogButton("Close").click
Exit Do
End If
'Handle 'Cancel' dialog appearing on the screen
If fGetDialogButton("Cancel").exist(0) Then
fGetDialogButton("Cancel").click
Exit Do
End If
'Handle Yes|No Dialog
If fGetDialogButton("&Yes").exist(0) AND fGetDialogButton("&No").exist(0) Then ' Ampersand symbol is intentional
strTemp = fExtractDialogMessage(fGetDialog())
'Handle 'do you want to close this window?' dialog
If InStr(1, strTemp, "Do you want to close this window") > 0 Then
fGetDialogButton("&Yes").click
Exit Do
End If
'Handle 'do you want to close this tab?' dialog
If InStr(1, strTemp, "Do you want to close this tab") > 0 Then
fGetDialogButton("&Yes").click
Exit Do
End If
End If
If Dialog("nativeclass:=#32770", "regexpwndtitle:=Visual Studio Just\-In\-Time Debugger", "index:=0").Exist(0) Then
Dialog("nativeclass:=#32770", "regexpwndtitle:=Visual Studio Just\-In\-Time Debugger", "index:=0").WinButton("text:=OK").Click
Exit Do
End If
'Closes Microsoft Document Imaging windows
If Window("nativeclass:=EPWindow", "index:=0").Exist(0) Then
' Window("nativeclass:=EPWindow", "index:=0").highlight
Window("nativeclass:=EPWindow", "index:=0").Close
wait(1)
Exit Do
End If
'Handle open browser
If Browser("index:=0").Exist(0) Then
Browser("index:=0").Close
Exit Do
End If
Loop
Loop
Function fGetDialog()
If Browser("index:=0").Dialog("nativeclass:=#32770", "index:=0").Exist(0) Then
' This is returning a normal Dialog with parent Browser
Set fGetDialog = Browser("index:=0").Dialog("nativeclass:=#32770", "index:=0")
Elseif Browser("index:=0").Dialog("nativeclass:=#32770", "regexpwndtitle:=Insert disk", "index:=0").Exist(0) Then
'This returns insert disk dialog only - sometimes a choose file and insert disk dialog is open at the same time which means the code in else will not work
Set fGetDialog = Dialog("nativeclass:=#32770", "regexpwndtitle:=Insert disk", "index:=0")
Else
'This is returning a Dialog with parent Dialog
'E.g.s of this - File Download dialog
Set fGetDialog = Dialog("nativeclass:=#32770", "regexpwndtitle:=File Download|Save as|Insert disk|Application Error|Microsoft Office Document Imaging", "index:=0")
End If
End Function
Function fGetDialogButton(ByVal strButtonText)
' Set fGetDialogButton = Browser("index:=0").Dialog("nativeclass:=#32770", "index:=0").WinButton("text:=" & strButtonText)
Set fGetDialogButton = fGetDialog().WinButton("text:=" & strButtonText)
End Function

You recon you could provide fExtractDialogMessage?
ReplyDelete