Jump to content

Identical windows with WinWait


poppe
 Share

Recommended Posts

Hello

I am automating the installation of my application.

I use winwait to wait for the next window to appear, then controlsend commands.

WinWait("Setup - My application","")
ControlSend("Setup - My application", "", "[CLASS:Button; INSTANCE:1]", "{ENTER}")
WinWait("Setup - My application","")
ControlSend("Setup - My application", "", "[CLASS:Button; INSTANCE:2]", "{ENTER}")
WinWait("Setup - My application","")
ControlSend("Setup - My application", "", "[CLASS:Button; INSTANCE:2]", "{ENTER}")

The window names are identical and winwait does not seem to like it.

In the help file it says i can use:

text

[optional] The text of the window to check.

Some of the windows have lots of text, for example: "You are now installing... etc. etc."

How can i identify the different windows with winwait?

What is the proper use of this text option?

Link to comment
Share on other sites

Thanks, but that function returns the same title as i get by using the info tool.

All the windows are identical Title: "Setup - my application" - Class: "TWizardForm"

WinWait does not know the difference between them, and the script runs through in an instant. It should always wait until the next window appears.

WinWait("Setup - My application","")
ControlSend("Setup - My application", "", "[CLASS:Button; INSTANCE:1]", "{ENTER}")
WinWait("Setup - My application","")
;
; script execution needs to wait at this point for the next window to appear, but now it does not.
;
; The application is unpacking files during this period, and the script
; should wait for that action to finish.
;
ControlSend("Setup - My application", "", "[CLASS:Button; INSTANCE:2]", "{ENTER}")
WinWait("Setup - My application","")
ControlSend("Setup - My application", "", "[CLASS:Button; INSTANCE:2]", "{ENTER}")

How can i make the script to wait for the next window to appear?

Edited by poppe
Link to comment
Share on other sites

  • 1 year later...

WinList()...loop through the returned array

WinList accepts any of these:

from helpfile: Window Titles and Text (Advanced)

  • TITLE - Window title
  • CLASS - The internal window classname
  • REGEXPTITLE - Window title using a regular expression (if the regular expression is wrong @error will be set to 2)
  • REGEXPCLASS - Window classname using a regular expression (if the regular expression is wrong @error will be set to 2)
  • LAST - Last window used in a previous AutoIt command
  • ACTIVE - Currently active window
  • X Y W H - The position and size of a window
  • INSTANCE - The 1-based instance when all given properties match

 

easiest way for installers is to do silent installs, or use text as well to ID windows.

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

If one shows up first, then WinWait() returns a "handle"... use that handle for that window.... The next window that shows up will have a different "handle". Now you have enough to differentiate the windows.... just apply logic.

Lar.

f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

Link to comment
Share on other sites

Try this:

Local $screen1HWND = WinWait("Setup - My application","")
If Not WinActive($screen1HWND) Then WinActivate($screen1HWND) ; This is just to make the script more robust and make sure the window is active before sending a command
ControlSend($screen1HWND, "", "[CLASS:Button; INSTANCE:1]", "{ENTER}")

Local $screen2HWND = WinWait("Setup - My application","")
If Not WinActive($screen2HWND) Then WinActivate($screen2HWND); This is just to make the script more robust and make sure the window is active before sending a command 
ControlSend($screen2HWND, "", "[CLASS:Button; INSTANCE:1]", "{ENTER}")

Local $screen3HWND = WinWait("Setup - My application","")
If Not WinActive($screen3HWND) Then WinActivate($screen3HWND); This is just to make the script more robust and make sure the window is active before sending a command
ControlSend($screen3HWND, "", "[CLASS:Button; INSTANCE:1]", "{ENTER}")
Edited by Shrapnel
Link to comment
Share on other sites

no point in answering the question of the original poster...this is a dug-up post.  Your script would potentially fail, if the first window is grabbed as the second window, since you do no wait for the first window to close first (could take upwards of a second to close, so you would grab the same button as the first, which is not going to fulfill the second window)...or, you should loop until the hwnd of the second window does not match that of the first.

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

Lol I didn't even look at the dates >_<

Anyways, good point on waiting for screen to close...

so it should be like this then, correct? (assuming {ENTER} closes the window)

Local $screen1HWND = WinWait("Setup - My application","")
If Not WinActive($screen1HWND) Then WinActivate($screen1HWND) ; This is just to make the script more robust and make sure the window is active before sending a command
ControlSend($screen1HWND, "", "[CLASS:Button; INSTANCE:1]", "{ENTER}")
Do
    Sleep(100)
Until Not WinExists($screen1HWND)

Local $screen2HWND = WinWait("Setup - My application","")
If Not WinActive($screen2HWND) Then WinActivate($screen2HWND); This is just to make the script more robust and make sure the window is active before sending a command
ControlSend($screen2HWND, "", "[CLASS:Button; INSTANCE:1]", "{ENTER}")
Do
    Sleep(100)
Until Not WinExists($screen2HWND)

Local $screen3HWND = WinWait("Setup - My application","")
If Not WinActive($screen3HWND) Then WinActivate($screen3HWND); This is just to make the script more robust and make sure the window is active before sending a command
ControlSend($screen3HWND, "", "[CLASS:Button; INSTANCE:1]", "{ENTER}")
Do
    Sleep(100)
Until Not WinExists($screen3HWND)
Edited by Shrapnel
Link to comment
Share on other sites

that should be safe :)...last thing I would add are fail safes, such as for application errors...so I would add timerinit/timerdiff on the do loops, so after a defined max time, the script can be ended (stop indefinite loops)...would also change those controlsends to controlclicks(but I know you just copied those in).

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

I Team,
I issue for idetifying same title windows.First window should wait till second window open .

How do i read content/text of second window .i will wait on first window only

First window Title: Configuration
Button on window: Ok ,Cancel and Next
Content or text on window: Welcome

Second window Title" Configuration
Button on window: Ok ,Cancel and Next
Content or text on window: USerinformation

How do i wait till second window appear .I want to read content/text on second window .

Please help me. I have define below below code .It will get

Local $screen1HWND = WinWait(" Client Configuration","&Next")
If Not WinActive($screen1HWND) Then WinActivate($screen1HWND) ; This is just to make the script more robust and make sure the window is active before sending a command
ControlSend($screen1HWND, "", "[CLASS:IRIS.bmpbutton; INSTANCE:1]", "{ENTER}")
Do
    Sleep(100) stop on second window

Until Not WinExists($screen1HWND)

Local $screen2HWND = WinWait("Client Configuration", "&Next")
If Not WinActive($screen2HWND) Then WinActivate($screen2HWND)
Send("459278")
Sleep(1000)
Send("{TAB}")
ControlSend($screen2HWND, "", "[CLASS:IRIS.bmpbutton; INSTANCE:1]", "{ENTER}")
Do
    Sleep(100)
Until Not WinExists($screen2HWND)

 

Link to comment
Share on other sites

Aniiii,

I am having trouble understanding what you want your script to do. Can you try to explain better exactly what you are trying to accomplish?

Also, when posting examples of AutoIt code, please use the code button in your post toolbar to format the text. it just makes it easier for everyone :)

Link to comment
Share on other sites

use this function:

winlist("yourtitle")

loop through the returned array for the window NOT equal to the hwnd of the first window...that's your new window

or, in your include Instance:2 in your winwait function

Use the helpfile for samples

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

Hi Sharpnel,

I want to configure the Messaging client i.e lotus notes automatically once user enter his details.

I have taken input from user and it should enter automatically on configuration window .

in this configuration we have Same Title window  ,and each window has different content .Now i want to identify content of window and wait the window or if error comes while configuring we have to display msg to user cant be processed .

Eg of window contains

First window Title: Configuration
Button on window: Ok ,Cancel and Next
Content or text on window: Welcome

Second window Title" Configuration
Button on window: Ok ,Cancel and Next
Content or text on window: User information

 

Third window Title" Configuration
Button on window: Ok ,Cancel and Next

Content/text on window : Local Area network

 

Now above example .

I want to wait till second window appear .Some time it will open other ERROR window  .IF error window come i have to  Exit .

Local $screen1HWND = WinWait(" Client Configuration","&Next")
If Not WinActive($screen1HWND) Then WinActivate($screen1HWND) ; This is just to make the script more robust and make sure the window is active before sending a command
ControlSend($screen1HWND, "", "[CLASS:IRIS.bmpbutton; INSTANCE:1]", "{ENTER}")
Do
    Sleep(100) stop on second window

Until Not WinExists($screen1HWND)

Local $screen2HWND = WinWait("Client Configuration", "&Next")
If Not WinActive($screen2HWND) Then WinActivate($screen2HWND)
Send("459278")
Sleep(1000)
Send("{TAB}")
ControlSend($screen2HWND, "", "[CLASS:IRIS.bmpbutton; INSTANCE:1]", "{ENTER}")
Do
    Sleep(100)
Until Not WinExists($screen2HWND)
Link to comment
Share on other sites

Aniiii,

Try this and let me know what happens. you will have to add some code, but it should get you pointed in the right direction:

Local $screen1HWND = WinWait(" Client Configuration","&Next")
If Not WinActive($screen1HWND) Then WinActivate($screen1HWND)
ControlClick($screen1HWND, "", "[CLASS:IRIS.bmpbutton; INSTANCE:1]", "left", 1)
Local $nextWindow = getNextWinTitle($screen1HWND) ; pass the handle of the window you just closed. it will return the next active window

; Now that you have the handle of the new active window, you can figure out if it is an error
; message, or if it is the "User Information" window and handle accordingly with an "If" statement

If WinGetTitle($nextWindow) = "Client Configuration" Then
    Local $screen2HWND = WinWait("Client Configuration", "&Next")
    If Not WinActive($screen2HWND) Then WinActivate($screen2HWND)
    Send("459278")
    Sleep(1000)
    Send("{TAB}")
    ControlClick($screen1HWND, "", "[CLASS:IRIS.bmpbutton; INSTANCE:1]", "left", 1)
    Do
        Sleep(100)
    Until Not WinExists($screen2HWND)
ElseIf WinGetTitle($nextWindow) = "Error" Then
    MsgBox(0, "", "Error message!")
    Exit
Else
    MsgBox(0, "", "Unexpected window!")
    Exit
EndIf


; getNextWinTitle function will wait until the provided window no longer
; exists and then gives you the handle of the new active window
Func getNextWinTitle($_originalWindowHWND)
    Local $originalWinTitle = WinGetTitle($_originalWindowHWND)
    Local $nextWinTitle = ""
    Do
        Sleep(100)
        $nextWinTitle = WinGetTitle("[active]")
    Until $nextWinTitle <> $originalWinTitle
    Return $nextWinTitle
EndFunc
Edited by Shrapnel
Link to comment
Share on other sites

HI,

Find the below code

Send("#r")
WinWaitActive("Run")
Send("notes.exe{Enter}")

Local $screen1HWND = WinWait("IBM Lotus Notes 8.5.2 Client Configuration","&Next")
If Not WinActive($screen1HWND) Then WinActivate($screen1HWND)
ControlClick($screen1HWND, "", "[CLASS:IRIS.bmpbutton; INSTANCE:1]", "left", 1)
Local $nextWindow = getNextWinTitle($screen1HWND) ; pass the handle of the window you just closed. it will return the next active window

; Now that you have the handle of the new active window, you can figure out if it is an error
; message, or if it is the "User Information" window and handle accordingly with an "If" statement

If WinGetTitle($nextWindow) = "IBM Lotus Notes 8.5.2 Client Configuration" Then
    Local $screen2HWND = WinWait("IBM Lotus Notes 8.5.2 Client Configuration", "&Next")
    If Not WinActive($screen2HWND) Then WinActivate($screen2HWND)
    Send("459278nkj")
    Sleep(1000)
    Send("{TAB}")
    Send("IBRT.MAgic.com)
    ControlClick($screen1HWND, "", "[CLASS:IRIS.bmpbutton; INSTANCE:1]", "left", 1)
    Do
        Sleep(100)
    Until Not WinExists($screen2HWND)
ElseIf WinGetTitle($nextWindow) = "IBM Lotus Notes" Then
    MsgBox(0, "", "Error message!")
    Exit
Else
    MsgBox(0, "", "Unexpected window!")
    Exit
EndIf


; getNextWinTitle function will wait until the provided window no longer
; exists and then gives you the handle of the new active window
Func getNextWinTitle($_originalWindowHWND)
    Local $originalWinTitle = WinGetTitle($_originalWindowHWND)
    Local $nextWinTitle = ""
    Do
        Sleep(100)
        $nextWinTitle = WinGetTitle("[active]")
    Until $nextWinTitle <> $originalWinTitle
    Return $nextWinTitle
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...