Jump to content

Identify Popup windows of a specific Window Handle


Recommended Posts

I have been using Auto IT along with the IUIAutomation for the nasty bits to perform automation in the Trizetto Facets application and everything is going well, until I was asked to use some of my scripts to generate Load on the system. 

In order to do this, I would need to Launch My AutoIT script "which opens the Facets application" multiple times.  Each time it is launched a new Facets App on the same computer will open.

Couple problems with this that I'm hoping someone will be able to help me out with

  1. On Launch of Facets, I get the PID from Shellexecute which I can then pass into the IUIA to search the proper window which is great, but the Click and Send functions from IUIA don't actually send directly to the control so It can get flaky when 5+ Facets screens are being controlled at the same time.
  2. On Launch of Facets, I use the PID to then get the Windows Hwnd.  When trying to do ControlClick, or Control* I can't seem to find any of the Popup windows such as the Database Select, or Login Creds using the Handle from the Main App and text from the Pop window. ex... ControlClick($MainUIhwnd, "text from popup", "Button1")  Is there some other way to identify popup windows for ControlClick type functions?

 

Link to comment
Share on other sites

Update:  

Still unsure how to handle #1 above, but for my #2 above, I have found a rather complicated process, but it works and seems to be reliable.

I'll have to do this every time I interact with a popup so I'll probably put this into a separate function.

;Open the targeted Facets environment
    ConsoleWrite("File > Open" & @CRLF)
    WinMenuSelectItem($hFacets, "", "&File", "&Open Database")

;Find the Open Product window and specify the Database
    $bChild = False
    For $c = 1 to 10
        ConsoleWrite("$hFacets Handle = " & $hFacets & @CRLF)

        $hOpenHwnd = WinWait("Open Facets Product", "", 5)              ;Loop up to 10 times looking for the Open Facets Product, below process ensures it's the one for this script.
        If $hOpenHwnd <> 0 Then
            ConsoleWrite("Found the Open Facets Product window" & @CRLF)

            ;$bChild = _WinAPI_IsChild($hOpenHwnd, $hFacets)            ;Always returns 0 even though I can match properly using the GetParent!!!
            ;ConsoleWrite("is Popup a child:  " & $bChild & @CRLF)

            $hParent = _WinAPI_GetParent($hOpenHwnd)
            ConsoleWrite("The Open Facets Product Parent = " & $hParent & @CRLF)

            If $hParent = $hFacets Then
                $bChild = True
                ExitLoop
            EndIf

        Else
            ConsoleWrite("Error, Couldn't find the Open Facets Product window " & @CRLF)
            ContinueLoop
        EndIf
    Next

    If $bChild <> True Then Exit 1


;Select the database we want to use.
    ControlSetText($hOpenHwnd, "", "Edit1", $sDatabase)                     ;Type out the full path to the database we want
    sleep(250)
    ControlClick($hOpenHwnd, "", "Button1")                                 ;Click the Open button
    sleep(500)


;Log onto the selected Database
    $bChild = False
    For $c = 1 to 10
        ConsoleWrite("$hFacets Handle = " & $hFacets & @CRLF)

        $hLogonHwnd = WinWait("Logon", "", 5)               ;Loop up to 10 times looking for the Open Facets Product, below process ensures it's the one for this script.
        If $hLogonHwnd <> 0 Then
            ConsoleWrite("Found the Logon window" & @CRLF)

            ;$bChild = _WinAPI_IsChild($hLogonHwnd, $hFacets)           ;Always returns 0 even though I can match properly using the GetParent!!!
            ;ConsoleWrite("is Popup a child:  " & $bChild & @CRLF)

            $hParent = _WinAPI_GetParent($hLogonHwnd)
            ConsoleWrite("The Logon Parent = " & $hParent & @CRLF)

            If $hParent = $hFacets Then
                $bChild = True
                ExitLoop
            EndIf

        Else
            ConsoleWrite("Error, Couldn't find the Logon window " & @CRLF)
            ContinueLoop
        EndIf
    Next

    If $bChild <> True Then Exit 1

    ;Log into the database
    ControlSetText($hLogonHwnd, "", "Edit3", $sUserName)                                    ;Type in the UserID
    ;sleep(250)
    ControlSetText($hLogonHwnd, "", "Edit4", $sPassword)                                    ;Type in the Password
    ;sleep(250)
    ControlClick($hLogonHwnd, "", "Button1")                                                ;Click OK to login

 

Link to comment
Share on other sites

I have lots of functions like this at work...If I remember, I'll bring them back tomorrow...but another good one to look into:

#include <WinAPI.au3>
_WinAPI_GetWindow ( $hWnd, $iCmd )

 

Use $iCmd = 6, where you pass in the parent window's handle...it will always return the processes current 'Enabled Popup' window handle (class something like #32700...could be a bit off...adding this off of memory)...you can use _WinAPI_GetWindow to get the 'parent window' as well

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

10 hours ago, jdelaney said:

#include <WinAPI.au3>
_WinAPI_GetWindow ( $hWnd, $iCmd )

jdelaney,  Thanks for the info, and that function works but I have to include it as part of a loop to wait for the window and also add additional steps to ensure it's the popup window I want.  I'm going to stick with my function posted above for now.  I think I'm going to use _WinAPI_GetWindow as part of my cleanup function to close any popup window.

Link to comment
Share on other sites

That's going to be a standard for all scripting.  There are generally granular functions that you want to use, that you have to wrap with a timer (loop) to do exactly what is required.

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
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

×
×
  • Create New...