topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Thursday December 12, 2024, 7:08 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: AHK - Wait functions don't really wait  (Read 20947 times)

nosh

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 1,441
    • View Profile
    • Donate to Member
AHK - Wait functions don't really wait
« on: August 13, 2008, 01:07 AM »
I've never been able to make functions like WinWait, WinWaitActive, WinWaitNotActive really work for me. AHK just doesn't seem to wait for the window - it doesn't matter whether I use the ahk_class or title to identify the window... I don't set any seconds timeout either... AHK zips right past the wait fns and executes the following commands anyway. I've been dealing with this using Sleep calls which is a bit of a dirty hack. Is there any way to make the wait fns actually wait?

Usage example:
WinClose, desktop38.ico
WinWaitNotActive, desktop38.ico      

(desktop38.ico is a valid window title)            
                     

 

Target

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,832
    • View Profile
    • Donate to Member
Re: AHK - Wait functions don't really wait
« Reply #1 on: August 13, 2008, 06:29 PM »
if you're closing a window (as in the above example) try ifwinexist/ifwinnotexist

stupid question, but have you looked at the window(s) using a window spy app?

You can use the one that comes with AHK, or try Toralf's version here http://www.autohotke...orum/topic12338.html

nosh

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 1,441
    • View Profile
    • Donate to Member
Re: AHK - Wait functions don't really wait
« Reply #2 on: August 13, 2008, 11:17 PM »
Yes, I have been using AHK spy. It's doesn't seem like a matter of identifying the window though - everything works as intended if I use a Sleep command. I generally use spy but some windows keep being assigned different class names on each run so I have to use the title in those cases. I'll give the alternative spy app a try though, thanks for the link.

Regarding IfWinExist: I need the first window to close before the subsequent commands are executed or they are performed on the first window itself, despite my using WinActivate to activate the intended target window. Making the WinClose conditional should just make the program ignore the command altogether, having the same effect. I don't suppose there's a way to direct a Send command to a specific window only, rather than whichever window is active?

; Inserting a Sleep at this point makes the code run as intended
WinClose, desktop38.ico
WinActivate, CompuPic Pro - USER
Send {Alt}oo{Enter}   



Target

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,832
    • View Profile
    • Donate to Member
Re: AHK - Wait functions don't really wait
« Reply #3 on: August 14, 2008, 01:09 AM »
i did say it was a stupid question... :-[

how about winwait close?

or maybe lookat SetTitleMatchMode?

does your target app have child windows (ala Excel)?  A colleague here has been trying to do something similar and is having problems cos he can't ID the relevant 'child' window (ie all windows appear the same to AHK)

nosh

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 1,441
    • View Profile
    • Donate to Member
Re: AHK - Wait functions don't really wait
« Reply #4 on: August 14, 2008, 09:33 AM »
WinWaitClose by itself bombs badly but, a

WinWait, desktop38.ico
WinClose, desktop38.ico
WinWaitClose, desktop38.ico

combination seems to do the trick.  :Thmbsup: Thanks for helping me out.

Target

  • Honorary Member
  • Joined in 2006
  • **
  • Posts: 1,832
    • View Profile
    • Donate to Member
Re: AHK - Wait functions don't really wait
« Reply #5 on: August 16, 2008, 05:28 AM »
you're most welcome :Thmbsup:

j.smith1981

  • Participant
  • Joined in 2009
  • *
  • default avatar
  • Posts: 1
    • View Profile
    • Donate to Member
Re: AHK - Wait functions don't really wait
« Reply #6 on: August 10, 2009, 04:55 AM »
I have a problem with an autohotkey app, thats sort of related to an issue like this.

Its beginning really to annoy me, but I thought I'd give it one last shot.

This is my code for the macro:

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

; this tests to makesure browser closes and fill in the gaps!

#include C:\autohkeyLIB\COM.ahk

COM_Init()
browser := COM_CreateObject("InternetExplorer.Application")
COM_Invoke(browser , "Visible=", "True") ;"False" ;"True" ;
url:="http://subdomain.mysite.co.uk/admin/home.php" ; navigates to ecommerce x cart!

COM_Invoke(browser, "Navigate", url)
loop
{
      If (rdy:=COM_Invoke(browser,"readyState") = 4)
      break ; once browser is in completed/ready state declared by readyState4 then break out of loop!
}

sleep 500 ; waits 10 seconds to make sure it has loaded!

; loads info into fields working
COM_Invoke(itemq:=COM_Invoke(all1:=COM_Invoke(document:=COM_Invoke(browser,"Document"),"All"),"Item","username"),"value","jeremy")
COM_Invoke(itemq:=COM_Invoke(all1:=COM_Invoke(document:=COM_Invoke(browser,"Document"),"All"),"Item","password"),"value","s56pj989")
sleep 10000 ; waits 5 seconds to make sure it has loaded into fields!
COM_Invoke(all1:=COM_Invoke(document:=COM_Invoke(browser,"Document"),"All"),"authform.submit()",javaScript) ; submits information

sleep 10000

loop
{
      If (rdy:=COM_Invoke(browser,"readyState") = 4)
      break ; once browser is in completed/ready state declared by readyState4 then break out of loop!;

}
 
url:="http://mysubdomain.mydomain.com" ; navigates to import page
COM_Invoke(browser, "Navigate", url)
loop
{
      If (rdy:=COM_Invoke(browser,"readyState") = 4)
      break ; once browser is in completed/ready state declared by readyState4 then break out of loop!
}

 sleep 5000

COM_Invoke(itemq:=COM_Invoke(all1:=COM_Invoke(document:=COM_Invoke(browser,"Document"),"All"),"Item","delimiter"),"value",",")
COM_Invoke(itemq:=COM_Invoke(all1:=COM_Invoke(document:=COM_Invoke(browser,"Document"),"All"),"Item","source_server"),"checked","checked")
COM_Invoke(itemq:=COM_Invoke(all1:=COM_Invoke(document:=COM_Invoke(browser,"Document"),"All"),"Item","localfile"),"value","/var/www/html/xcart/files/UPLOADcategories.csv")

sleep 5000 ; waits 5 seconds to make sure it has loaded into fields!
COM_Invoke(item83:=COM_Invoke(all3:=COM_Invoke(document:=COM_Invoke(browser,"Document"),"All"),"Item","submit"),"click")

sleep 10000

 loop
 {
       If (rdy:=COM_Invoke(browser,"readyState") = 4)
      break ; once browser is in completed/ready state declared by readyState4 then break out of loop!
 }

; macro will process the file using sleep command but isnt the most robust solution in the world!

; to then process another file

COM_Invoke(browser, "Quit")
COM_Term()

Basically what it does is there's a file uploaded to our server for a products update on our ecommerce, thats done in a previous program (wouldnt really be the best solution doing this in AHK because its rather slow, the upload that is, would take about an hour or so to complete).

The way I went about it in the above code is, it sends a click instruction to the COM object variable Internet Explorer, it then waits for the file to be processed, and then reads back with the html tage as follows:

<tr>
<td class="DialogInfoBorder">
<table cellspacing="1" width="100%">

<tr>
<td valign="top" class="DialogBox"><div id="status_message">Data has been imported successfully.</div>
</td>
</tr>
</table></td>
</tr>

The problem is, because its on a sleep function/timer whatever you want to call it, if the update takes allot longer on day x or more importantly the 11th hour its been running that day (just for an example), and it closes the application as the 'COM_Invoke(browser, "Quit")' depicts (excuse spelling), it will fail on the upload.

What I want it to do, when it notices that the above html tag exists with that value, is process another csv file.

This is what I am looking for AHK to detect is there 'Data has been imported successfully.'

This would make this program/macro rather robust I think.

Any ideas of how to get around this?

Just want to make this the most robust application ever, is quite important that this runs accurately first time without failing or I end up in my job praying it wont fall over.

The process another file would involve another command similar to this:

url:="http://mysub.mydomain.co.uk/admin/import.php" ; navigates to import page
COM_Invoke(browser, "Navigate", url)
loop
{
      If (rdy:=COM_Invoke(browser,"readyState") = 4)
      break ; once browser is in completed/ready state declared by readyState4 then break out of loop!
}

 sleep 5000

COM_Invoke(itemq:=COM_Invoke(all1:=COM_Invoke(document:=COM_Invoke(browser,"Document"),"All"),"Item","delimiter"),"value",",")
COM_Invoke(itemq:=COM_Invoke(all1:=COM_Invoke(document:=COM_Invoke(browser,"Document"),"All"),"Item","source_server"),"checked","checked")
COM_Invoke(itemq:=COM_Invoke(all1:=COM_Invoke(document:=COM_Invoke(browser,"Document"),"All"),"Item","localfile"),"value","/var/www/html/xcart/files/UPLOADcategories.csv")

sleep 5000 ; waits 5 seconds to make sure it has loaded into fields!
COM_Invoke(item83:=COM_Invoke(all3:=COM_Invoke(document:=COM_Invoke(browser,"Document"),"All"),"Item","submit"),"click")
[code]

But then it would wait for the same tag:

''

To know when to close the application, can someone come up with a solution, attempted about 6 things to get around this but it always keeps coming back to a timer, not the best solution I've come up with ever.

Any ideas?
[/code]
« Last Edit: March 29, 2012, 03:34 PM by j.smith1981 »

Stefano44

  • Participant
  • Joined in 2009
  • *
  • default avatar
  • Posts: 1
    • View Profile
    • Donate to Member
Re: AHK - Wait functions don't really wait
« Reply #7 on: October 02, 2009, 08:06 AM »
I don't know about how servers/csv/etc work, but are you using the browser (IE) to download the .csv files to your local pc (which is on LAN)?
Or is it being loaded into the browser window?