Jump to content

Manipulating a Windows dialog box generated byan embedded IE session


7rip
 Share

Recommended Posts

I'm working on a project to automate a web application in IE. The app is buried inside frames and is an authenticated session. While I may be able to do it more elegantly in the future, for the time being I'm trying to make it through using mouse clicks and send commands.

So far everything is working well. I am trying to accommodate variances in IE on different PCs. Screen resolution, tool bars, etc. To accomplish this I want to embed IE inside a GUI since that strips any extras on the browser and I can control the size of the GUI container so that coordinating mouse movement relative to the window is consistent.

The problem I am running into, and have not been able to get around, is that while navigating inside this web app, I will sometimes encounter pop up dialog box. Before I embedded the browser, I was able to take care of the dialog boxes by issuing a WinExist / WinKill command sequence. Once I embedded the browser though, the same WinExist / WinKill sequence isn't working. Once one of these dialog boxes pops up the script will sit in a paused state until the dialog box is cleared manually. I've run through pretty much every function I thought might see or act on the dialog box but without any luck.

Because the application is secured and highly confidential, I am unable to post an example that interacts with the application directly. I did however, create two examples using the bare minimum of web code and AutoIt code that will reproduce the same situation as the live app.

I'm hoping that someone might have seen this before and/or might have some ideas on how to accomplish my goal.

Example 1 opens up IE, navigates to the example page I've created then mouseclicks on a button that will generate the type of dialog box I need to address. I am able to kill this dialog box with the WinExist / WinKill sequence.

#include <IE.au3>

Opt ("MouseCoordMode", 0) 

_IECreate ("littlecitysupport.com/au3/example.html")

MsgBox (0, "Notice", "2 seconds after closing this message box, AutoIt3 will left click a button that creates a dialog box." & @CRLF & "Two seconds after that, the dialog box will get killed using WinKill" & @CRLF & "You may have to adjust the mouse coordinates for your PC/browser.")
Sleep(2000)
MouseClick ("left", 155, 155, 1, 10)
Sleep(250)

;Check if message box appears & kill it if it does
If WinExists("Windows Internet Explorer") then
    Sleep(2000)
    WinKill("Windows Internet Explorer", "")
    Sleep(250)
EndIf

Example 2 embeds IE inside a GUI then opens up the same example page. Again, using mouseclicks, the button is pushed and the dialog box opens but in this case the WinExist / WinKill sequence are not able to see/kill the dialog box.

#include <GUIConstantsEx.au3>
#include <IE.au3>

;Mouse coordinates relative to the active window
Opt ("MouseCoordMode", 0)

;Create GUI object & embed IE inside
$oIE = _IECreateEmbedded ()
GUICreate("Example", 640, 580)
    $GUIActiveX = GUICtrlCreateObj($oIE, 10, 40, 620, 500)
GUISetState()

;Open example URL
_IENavigate ($oIE, "http://littlecitysupport.com/au3/example.html")

;Message box with delay and intention information
MsgBox (0, "Notice", "2 seconds after closing this message box, AutoIt3 will left click a button that creates a dialog box." & @CRLF & "This is the dialog box I need to be able to kill.")
Sleep(2000)
MouseClick ("left", 165, 100, 1, 10)
Sleep(1000)

;Check if message box appears & kill it if it does
If WinExists("Windows Internet Explorer", "") then
    Sleep(2000)
    WinKill("Windows Internet Explorer", "")
    Sleep(250)
EndIf

;Loop to keep GUI open
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
WEnd
GUIDelete()
Exit

The attachment is just the same 2 examples, as au3 files, zipped together.

example_7rip.zip

Link to comment
Share on other sites

This worked on your test program #2

#include <GUIConstantsEx.au3>
#include <IE.au3>

;Mouse coordinates relative to the active window
Opt("MouseCoordMode", 0)

;Create GUI object & embed IE inside
$oIE = _IECreateEmbedded()
GUICreate("Example", 640, 580)
$GUIActiveX = GUICtrlCreateObj($oIE, 10, 40, 620, 500)
GUISetState()

;Open example URL
_IENavigate($oIE, "http://littlecitysupport.com/au3/example.html")

;Message box with delay and intention information
MsgBox(0, "Notice", "2 seconds after closing this message box, AutoIt3 will left click a button that creates a dialog box." & @CRLF & "This is the dialog box I need to be able to kill.")
Sleep(2000)

;Check if message box appears & kill it if it does
KillWindow()
MouseClick("left", 165, 100, 1, 10)
Sleep(1000)



;Loop to keep GUI open
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
    EndSelect
WEnd
GUIDelete()
Exit

Func KillWindow()
    $a = ""
    $a &= 'WinWait("Windows Internet Explorer", "")' & @CRLF
    $a &= 'If WinExists("Windows Internet Explorer", "") then' & @CRLF
    $a &= 'Sleep(2000)' & @CRLF
    $a &= 'WinKill("Windows Internet Explorer", "")' & @CRLF
    $a &= 'Sleep(250)' & @CRLF
    $a &= 'EndIf' & @CRLF

    Local $file_loc = @ScriptDir & "\Killer.au3"
    FileDelete($file_loc)
    FileWrite($file_loc, $a)

    If @Compiled = 1 Then
        $file_exe = FileGetShortName(@AutoItExe & ' /AutoIt3ExecuteScript "' & $file_loc & '"')
        Run($file_exe)
    Else
        $file_au3 = FileGetShortName($file_loc)
        Run(@AutoItExe & " " & $file_au3, "", @SW_HIDE)
    EndIf
EndFunc   ;==>KillWindow

8)

NEWHeader1.png

Link to comment
Share on other sites

As a stand-alone Function, just use the title of the new window

Func KillWindow($title)
    Local $Script = 'WinWait("' & $title & '", "")' & @CRLF & 'WinKill("' & $title & '", "")' 
    Local $file_loc = @ScriptDir & "\Killer.au3"
    FileDelete($file_loc)
    FileWrite($file_loc, $Script)
    If @Compiled = 1 Then
        $file_exe = FileGetShortName(@AutoItExe & ' /AutoIt3ExecuteScript "' & $file_loc & '"')
        Run($file_exe)
    Else
        $file_au3 = FileGetShortName($file_loc)
        Run(@AutoItExe & " " & $file_au3, "", @SW_HIDE)
    EndIf
EndFunc   ;==>KillWindow

8)

NEWHeader1.png

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...