Welcome Guest.   Make a donation to an author on the site July 29, 2014, 08:01:28 PM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
The N.A.N.Y. Challenge 2014! Download dozens of custom programs!
   
  Forum Home Thread Marks Chat! Downloads Search Login Register  
  Show Posts
      View this member's profile 
      donate to someone Donate to this member 
Pages: [1]
1  Other Software / AutoHotkey / Re: AHK - Wait functions don't really wait on: August 10, 2009, 04:55:56 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:

[copy or print]
#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:

[copy or print]
<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:

[copy or print]
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]
Pages: [1]
DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.025s | Server load: 0.26 ]