Jump to content

[Solved] Winwait (strange behavior?)


Recommended Posts

Hello to all, and thanks for looking at this questions.

Where this questions comes from.

I am trying to use Winwait to (wait for it) wait for a window to appear. :D

 

I use this example form the help file.

Example()

Func Example()
    ; Run Notepad
    Run("notepad.exe")

    ; Wait 10 seconds for the Notepad window to appear.
    WinWait("[CLASS:Notepad]", "", 10)

    ; Wait for 2 seconds to display the Notepad window.
    Sleep(2000)

    ; Close the Notepad window using the classname of Notepad.
    WinClose("[CLASS:Notepad]")
EndFunc   ;==>Example
WinWait("[CLASS:Notepad]", "", 10)

^ That is is set to time out in 10 seconds?

I run this script in Scite.

>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "Q:\!Autoit\5678.au3" /UserParams    
+>13:36:33 Starting AutoIt3Wrapper v.17.224.935.0 SciTE v.3.7.3.0   Keyboard:00000409  OS:WIN_10/  CPU:X64 OS:X64  Environment(Language:0409)  CodePage:0  utf8.auto.check:4
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper
>Running AU3Check (3.3.14.2)  from:C:\Program Files (x86)\AutoIt3  input:Q:\!Autoit\5678.au3
+>13:36:33 AU3Check ended.rc:0
>Running:(3.3.14.2):C:\Program Files (x86)\AutoIt3\autoit3.exe "Q:\!Autoit\5678.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
+>13:36:36 AutoIt3.exe ended.rc:0
+>13:36:36 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 2.89

Notice the time is at  2.89 (seconds?). It should wait (close to) 10 seconds before doing any (waiting for window to appear)?

Please help as I am so confused with this, I made the rest work, and I am getting stuck on waiting for a window!! :'(:angry:

 

 

Edited by NoobieAutoitUser
Link to comment
Share on other sites

  • Developers
5 minutes ago, NoobieAutoitUser said:

Notice the time is at  2.89 (seconds?). It should wait (close to) 10 seconds before doing any (waiting for window to appear)?

Wait should it wait when you run Notepad?  
the 2.89 seconds comes from execution time and the 2 seconds sleep.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

 

2 minutes ago, NoobieAutoitUser said:

I am thinking I don't understand the concept of Winwait.

Then you need to stop thinking and start reading that helpfile page I already copied and posted into the other thread. 
This time read the whole lot, but especially the very first line carefully and tell me which part is still unclear after that! 

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

WinWait

Pauses execution of the script until the requested window exists.

WinWait ( "title" [, "text" [, timeout = 0]] )
Parameters
title   The title/hWnd/class of the window to check. See Title special definition.
text    [optional] The text of the window to check. Default is an empty string. See Text special definition.
timeout     [optional] Timeout in seconds if the window does not exist. Default is 0 (no timeout).

Winwait is to 'pause' until said 'notepad' exists, and it waits till the time out? Winwait gives notepad 10 seconds to come into existence?

What happens if 'notepad' does not exist within the timeout?

I feel very stupid with this :D

Link to comment
Share on other sites

  • Developers
3 minutes ago, NoobieAutoitUser said:

What happens if 'notepad' does not exist within the timeout?

You know the answer to that as that was yesterday already answered by me... and is answered in the helpfile page so just re-read it!

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Hi.

Normally WinWait is pausing the whole script until the defined window appears. But you can define a timeout in seconds. After that the script is running the next steps.

So WinWait("Notepad", "", 10) means. Wait until there is a window named "Notepad". If it is there then go ahead immediately. But wait only 10 seconds for the window "Notepad". After 10 seconds resume the script. No matter if the window "Notepad" exists or not.

So in your script you run Notepad and you are waiting for it maximal 10 seconds. But as you can see in the console running Notepad needs only 0,89 seconds. So you don't have to wait furthermore and the next step Sleep(2000) will do then. That's 2,89 seconds in total. 

Is it clear now? Regards, Conrad

SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win_10   Build = 19044   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Link to comment
Share on other sites

33 minutes ago, Simpel said:

Hi.

Normally WinWait is pausing the whole script until the defined window appears. But you can define a timeout in seconds. After that the script is running the next steps.

So WinWait("Notepad", "", 10) means. Wait until there is a window named "Notepad". If it is there then go ahead immediately. But wait only 10 seconds for the window "Notepad". After 10 seconds resume the script. No matter if the window "Notepad" exists or not.

So in your script you run Notepad and you are waiting for it maximal 10 seconds. But as you can see in the console running Notepad needs only 0,89 seconds. So you don't have to wait furthermore and the next step Sleep(2000) will do then. That's 2,89 seconds in total. 

Is it clear now? Regards, Conrad

Finally :) I understand now.
I thought it paused until the window existed, and timed out the script. I was pulling my hair out :)
Thanks so much.

How do I make a script wait for a window and exit if not ?

Winwait does not work like I thought it did, so how to do this ?

I'm thinking a loop (x seconds). If 'winexsits' ?

Link to comment
Share on other sites

Hi.

I have been messing with this for a few days now. My head feels like scrambled eggs :drool:

The 'code' finally works :DB)

I think it was a combination of a few things, and that the window name has an exclamation point in it. Notice I used ' instead of " around !My-Cell.

Now it waits for 5 seconds, if window does not appear, it exits the script.

Thanks to all for help, and for having patience.

$hWnd = WinWait('!My-Cell', "", 5)
sleep(5000)
If WinExists($hWnd) Then
  MsgBox(0, "", "Window exists")
Else
  MsgBox(0, "", "Window does not exist")
  Exit
EndIf

 

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