Jump to content

Get the Title of Pop Up appeared


Go to solution Solved by Soundarya,

Recommended Posts

Hello All, I am automating a desktop application. In mid of the process I am getting a Pop-Up and I have to capture the Title of the popup window and do a If loop to check the title. I tried multiple ways, (To get the Title of Active Window, Title of last Window and using the Class name (CLASS:#32770)) but nothing worked.

I tried to retrieve the Tittle of Class name (CLASS:#32770) and it was a different title. So doubt if there are multiple Windows with same Class name. Can any one help me to get the Title of pop up generated from my desktop application.

Edited by Soundarya
Link to comment
Share on other sites

My suggestion without knowing more would that you could use an array of all windows (WinList() with no parameters). Each loop, get a new array of all windows and compare them both, looking for new windows. Then do whatever other checks on any new windows to see if it's the one you want. If not, store the new array to use to compare against in the next loop. Keep in mind that this approach feels fairly 'brute force'-y to me, and likely is not very performant.

Other options would be to check out these functions:

These functions all allow you to keep the amount of windows that they retrieve down if you pass in the parent information, and you can do a much smaller comparison set to what is mentioned above.

We ought not to misbehave, but we should look as though we could.

Link to comment
Share on other sites

@Nine

I want to handle the pop up displayed below and get its Title. I am also adding the Windows Info of the PopUp. I do not want to use the Title or Text to get the PopUp control. I actually do not want to give the Tittle or Text in pop up to get the handle because every time I receive different set of pop ups

image.png.42af1bf3b75d9724dd47dfc10cd45e6a.png

image.png.2e3bf06a40b7cc64e18d7be99769fe21.png

 

Edited by Soundarya
Link to comment
Share on other sites

@Nine

@mistersquirrle

 

I figured the problem. The second Window takes some time to popup, so it considered my parent window always when I tried to get the text of active Window. I implemented Sleep and it worked, as I know the loading time of 2nd window is always stable. Can you share your comments on using sleep function in our code ? 

Link to comment
Share on other sites

Generally, using Sleep to implement a pause to allow time for something specific to happen isn't the best option. While it may seem to always take x seconds for something to happen while you're testing your code, in real world operations your code may run on faster or slower hardware, the CPU or drive may be busy with something else, there may be a network bottleneck or interruption, or anything else to make your x second wait not work. If possible, it's best to find an event or trigger you can look for to tell you when to proceed.

(For example, when you get ready to go somewhere with a friend, rather than wait an arbitrary 5 minutes for them to be in the car before you drive away, you wait as long as it takes until you see them in the seat. That's your event or trigger to know that it's safe to proceed.)

The suggestion to watch for new windows to be created may provide you with just such an event.

Link to comment
Share on other sites

  • Solution

@ioa747 Thanks, in my case there are 2 different pop ups that occur on 2 different scenarios. I achieved by following below code

 

Func SubmitJCL($Control)
    ControlClick($Control,"",'[REGEXPCLASS:WindowsForms\d+\.BUTTON\.app\.\d+\..*?; INSTANCE:4]')        
    Sleep(1000)
    If WinExists("Submit JCL?","") Then
    Local $PopUp = WinWait("Submit JCL?","",0)
    ControlClick($PopUp, "","Button1")
    Else
    $Error = WinGetTitle('[Active]',"")
    $ErrorText = WinGetText('[Active]',"")
    ControlClick($Error, "","Button1")
    AppendToLogFile($Error,$ErrorText)
    EndIf    
EndFunc

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