Jump to content
Sign in to follow this  
shiv

How to handle the window twice

Recommended Posts

shiv

For $i = 1 To 10
        If WinExists("My window") Then
        ControlClick("My window","NO","[CLASS:Button; INSTANCE:1]")
        Sleep(2000)
        WinWaitActive("Check your window","test: yahoo.com",2)
        ControlClick("Check your window","test: yahoo.com","Button2")
ExitLoop
        EndIf
        Sleep(1000)
        Next

Some time "My window" is pop up 1 time and some time it is pop up twice.

The above code handle this window "My window" successfully for the 1st time its thrown but when it occurs 2nd time it unable to handle it.

Please provide some refactoring for the above code so that it can handle the pop up window "My window" 2 times

Share this post


Link to post
Share on other sites
JohnOne

while 1
        If WinExists("My window") Then
        ControlClick("My window","NO","[CLASS:Button; INSTANCE:1]")
        Sleep(2000)
        WinWaitActive("Check your window","test: yahoo.com",2)
        ControlClick("Check your window","test: yahoo.com","Button2")
;ExitLoop
        EndIf
        Sleep(1000)
wend


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
shiv

Hi John thanks a lot,

But suppose if window  "My Window" is not pop up , not for once then for how long would it wait for the window to exist.

And if window not exist then would it get stuck there or will execute my code further.

Actually in my application this window occurs after 2 days. so i just want to write a code which checks the presence of this window. if the window exist then it can handle it .(here the probability of occurring the window is 2 times)

thanks

Share this post


Link to post
Share on other sites
NewPlaza

The code above will wait 1 second.... Then loop again...

But if it does find 'MyWindow' then it will wait a maximum of 4 seconds for 'CheckYourWindow' to be active.

Edited by NewPlaza

Share this post


Link to post
Share on other sites
shiv

Its not only about that how long would it wait. PLEASE go through again my query above

Share this post


Link to post
Share on other sites
NewPlaza

How often do you run that bit of code?

Edited by NewPlaza

Share this post


Link to post
Share on other sites
JohnOne

Most code has a main while loop.

In the absence of solid information about when and when not your target window appears twice or how long you're prepared to wait for a second window, logic suggests you check for it infinitely in that main while loop.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


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
Sign in to follow this  

×