Jump to content

Differentiate between 3 different dialog boxes with same title but different text


Recommended Posts

Hi,

I have an application that creates multiple dialog boxes, depending on which file is being opened. In the majority of cases, the dialog box title is the same, but not always. I would like to automatically click specific buttons, depending on which dialog box appeared.

I have created a partial solution, which consists of 4 different files. One example:

ControlFocus("Foo","Static Text 1", "Static2")
ControlClick("Foo,"&Yes","Button1")

I basically have the same code in three mode files, with just the static text and buttons updated. Individually, they work fine. 

What I tried to do next is to have them permanently check if a dialog box comes up, since the application is started automatically through another program. Therefore, I extended each of my scripts like this:

While 1
    If WinExists("Foo") Then

        ControlFocus("Foo","Static Text 1", "Static2")
        ControlClick("Foo,"&Yes","Button1")
    
    EndIf
WEnd

The issue that I have now is that there is basically a race condition between them. Since some dialog boxes have the same title ("Foo"), whichever of my scripts finds it first will execute, which is not always the correct one for it's respective purpose. I would like to improve this and have two questions:

  1. How to check not only if a dialog box with a specific title exists, but also the text it contains (e.g., the Static2 or Static1 label text that it contains), so that I can trigger the correct action? I tried to search for a suitable function in https://www.autoitscript.com/autoit3/docs/functions.htm, but couldn't identify one that seemed appropriate to me.
  2. How to best combine all files in a single file? This should be easy once I know how to solve 1)

Any help would be much appreciated!

Link to post
Share on other sites

I had done something similar with a credential filler with VNC and Cisco VPN. What I did first was get a list of windows into an array:

$aWindows = WinList("[REGEXPTITLE:(?i)(.*foo.*)]")

Then search the array for the specific text of the window:

_ArraySearch($aWindows, "text to find", 0, 0, 0, 2)

Set up some if statements and you should be able to catch any conditions you want.

Link to post
Share on other sites
  • 1 month later...

I am still having difficulties in getting it working. My current code is like this:

 

#include <Array.au3>

While 1
    If WinExists("Test Program") Then
        $aWindows = WinList("[REGEXPTITLE:(?i)(.*Program*)]")

        If (_ArraySearch($aWindows, "Partial String 11", 0, 0, 0, 2)) Then
                    ControlClick("Partial String 11","&Yes","Button1")
        ElseIf (_ArraySearch($aWindows, "Partial String 22", 0, 0, 0, 2)) Then
                    ControlClick("Partial String 22","&No","Button2")
        ElseIf (_ArraySearch($aWindows, "Partial String 33", 0, 0, 0, 2)) Then
                    ControlClick("Partial String 33","&OK","Button1")
        EndIf
    EndIf
WEnd

 

I've also tried to put the complete string, not just partial strings, but that didn't help either. Any suggestions on how to implement it correctly? 

Link to post
Share on other sites

Looks like your:

ControlClick("Partial String 11","&Yes","Button1")

is missing the first argument. Should be title/hWnd/class of the window then the text. After "Partial String 11", the next arg should be the ControlID versus the text of the button. Then there's the optional arg of which button on the mouse is clicking ("left", "right", "middle", "main", "menu", "primary", "secondary". Default is the left button.)

So it should look more like this:

ControlClick ( "title", "text", controlID )

Assuming you'll be left clicking.

I'd try something more like this (not tested since I don't know the actual strings you're searching for nor the button classes/instances of the controls):

    While 1
        Sleep ( 200 )
        $aWindows = WinList ( "[REGEXPTITLE:(?i)(.*Program.*)]" )
        _ArrayAdd ( $aWindows , 0 )

        $iIndex = _ArraySearch ( $aWindows , "Test Program" , Default , Default , 0 , 1 )
        if @error then ContinueLoop

        $hWnd =  WinGetHandle ( $aWindows[$index][1] )
        if not @error Then
            MsgBox ( 0 , $index , $hWnd )
            ExitLoop
        EndIf
    WEnd

    if $hWnd <> Null Then 
        if WinExists ( $hWnd , "Partial String 11" ) then
            ControlClick($hWnd , "Partial String 11" , "[CLASS:Button; INSTANCE:1]")
        EndIf

        if WinExists ( $hWnd , "Partial String 22" ) then
            ControlClick($hWnd , "Partial String 22" , "[CLASS:Button; INSTANCE:1]")
        EndIf
    EndIf


 

 

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...