I am trying to automate status requests to a 3rd party vendor website at work. Currently I make my script wait 40 seconds after each action to wait for a page to load. (load time ranges from 1 second to a few minutes at very worst case).
Is there a way to make my script wait for IE to finish loading before proceeding?
I tried the code IELoad(wb)
from here, but it does not always work. (Sometimes it will just sit there, and I have to press F5). Last night I let it ran, and it stopped about 25 cases in.
Observation: The page will be loaded, but the IELoad(wb)
function is still waiting for something.
; You need to send the IE handle to the function unless you define it as global.
IELoad(wb) {
If !wb ;If wb is not a valid pointer then quit
Return False
Loop ;Otherwise sleep for .1 seconds untill the page starts loading
Sleep,100
Until (wb.busy)
Loop ;Once it starts loading wait until completes
Sleep,100
Until (!wb.busy)
Loop ;optional check to wait for the page to completely load
Sleep,500
Until (wb.Document.Readystate = "Complete")
Return True
}
wb := ComObjCreate("InternetExplorer.Application")
wb.Visible := True
wb.Navigate("www.someVendor.com")
IELoad(wb)
; This is the part I have the most problems with
wb.document.getElementById("someLink").click()
; The page might be loaded, but it will sit there and wait forever
IELoad(wb)
; Do some clicking and searching...
wb.Document.Body.innerHTML
and do some checks prior to clicking. Personally I moved away from AHK for web automation and now use to free tool Selenium (you may want to google that) which works much better with web sites that have a lot of javascript in them. – 576i