- Usually to be quick on a website I would do something like this, a simple check and a 500 msec wait for safety.
Code: Select all
while oWB.busy || !(oWB.readyState = 4) ;READYSTATE_COMPLETE := 4
Sleep, 10
Sleep, 500
- So I've been trying to repeatedly call methods until they succeed, leading to the code below.
- I've been wondering if people have other ideas, perhaps counting the number of elements with a certain tag/class, perhaps some query can be made to an element to check that it's ready.
- Also, I could do with a good example website that fails occasionally, for doing tests on. The example below just focuses Google's input field. Thanks.
Code: Select all
;WBGet function - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=39869
q:: ;try invoking a method multiple times, else display MsgBox
WinGet, hWnd, ID, A
oWB := WBGet("ahk_id " hWnd)
oWB.navigate("https://www.google.co.uk/")
SoundBeep
while oWB.busy || !(oWB.readyState = 4) ;READYSTATE_COMPLETE := 4
Sleep, 10
SoundBeep
oElt := oWB.document.getElementById("lst-ib")
if !JEE_ObjInvokeMethod(oElt, "focus")
MsgBox, % "error"
SoundBeep
oWB := ""
return
JEE_ObjInvokeMethod(oObj, vMethod, oParams*)
{
global vGblInvokeMethodDelay, vGblInvokeMethodTryCount
Loop, % vGblInvokeMethodTryCount ? vGblInvokeMethodTryCount : 10
{
if !(A_Index = 1)
Sleep, % vGblInvokeMethodDelay ? vGblInvokeMethodDelay : 50
try
{
oObj[vMethod](oParams*)
return 1
}
}
return 0
}