Internet Explorer: confirm a webpage has loaded

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Internet Explorer: confirm a webpage has loaded

19 Sep 2018, 10:41

- I've been doing some webpage automation on a webpage I have permission to automate as rapidly as possible.
- 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
- I've been experimenting with reducing the safety wait because I need a little more speed, but it leads to more errors.
- 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
}
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
MannyKSoSo
Posts: 440
Joined: 28 Apr 2018, 21:59

Re: Internet Explorer: confirm a webpage has loaded

19 Sep 2018, 11:06

For me when I was doing something similar I had a problem with a page and waiting for an element to load, so what I did was the following

Code: Select all

While IE.readyState!=4 || IE.document.readyState!="complete" || IE.busy
        Sleep 50
While (IE.document.getElementsByTagName("textarea")[1].value = "")
	Sleep 50
This does a check to make sure everything is ready and then it can move on to make sure the element exists and contains data (since the element I wanted was a translator and needed a second to translate the given data)

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: aitaixy, Anput, Google [Bot], Nerafius and 186 guests