topbanner_forum
  *

avatar image

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

Login with username, password and session length
  • December 13, 2019, 07:46 AM
  • Proudly celebrating 13 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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - j.smith1981 [ switch to compact view ]

Pages: [1]
1
AutoHotkey / Re: AHK - Wait functions don't really wait
« 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]

Pages: [1]