Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Determine if a WebPage is completely loaded in IE


  • Please log in to reply
75 replies to this topic
Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

pweb := COM_QueryService(pdoc,IID_IWebBrowserApp,IID_IWebBrowserApp)

Shouldn't that be IHTMLDocument or IHTMLDocument2?

What I meant was this:
;ControlGet, hIESvr, hWnd, , Internet Explorer_Server1, ahk_class IEFrame
MouseGetPos, , , , hIESvr, 2
If !hIESvr
   ExitApp
IID_IWebBrowserApp := "{0002DF05-0000-0000-C000-000000000046}"
COM_CoInitialize()
DllCall("SendMessageTimeout", "Uint", hIESvr, "Uint", DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT"), "Uint", 0, "Uint", 0, "Uint", 2, "Uint", 1000, "UintP", lResult)
DllCall("oleacc\ObjectFromLresult", "Uint", lResult, "Uint", COM_GUID4String(IID_IHTMLDocument2,"{332C4425-26CB-11D0-B483-00C04FD90119}"), "int", 0, "UintP", pdoc)
pweb := COM_QueryService(pdoc, IID_IWebBrowserApp, IID_IWebBrowserApp)
COM_Release(pdoc)


Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
I was somehow thinking in reverse (get pdoc from pweb,) but I see now what you meant by "can be used with any DOM objects." Useful to know; thanks. :)

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

Useful to know;

Actually this was the original code, the ReadyState used to be queried through pweb. I recently changed it to make the code simpler, but I realized I also removed some useful info. :oops:

Joy2DWorld
  • Members
  • 562 posts
  • Last active: Jun 30 2014 07:48 PM
  • Joined: 04 Dec 2006
ok, not exactly on topic, but,

can anyone explain the difference between
MouseGetPos, , , , hIESvr, 2
and
MouseGetPos, , , , hIESvr, 3


the doc's

specify one of the following digits:

1: Uses a simpler method to determine OutputVarControl. This method correctly retrieves the active/topmost child window of an Multiple Document Interface (MDI) application such as SysEdit or TextPad. However, it is less accurate for other purposes such as detecting controls inside a GroupBox control.

2 [v1.0.43.06+]: Stores the control's HWND in OutputVarControl rather than the control's ClassNN.

3 [v1.0.43.06+]: A combination of 1 and 2 above.

doesn't seem to register for me.

'cause it sure seems that 3 is giving the actual control handle, while 2 gives a container handle. or some such thing...
Joyce Jamce

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007

'cause it sure seems that 3 is giving the actual control handle, while 2 gives a container handle.

Both will give the window handle of the control, just will use different methods.
2 with the default method, 3 with the simpler method.

Erittaf
  • Members
  • 192 posts
  • Last active: Feb 28 2013 11:49 PM
  • Joined: 02 Nov 2007
Does anyone know of any difficulties running this on vista? I have a project that will be used on vista machines but I don't have vista at all. I want to use this function but I also need to be sure it will work.

Any vista users out there willing to test for me?

Erittaf
  • Members
  • 192 posts
  • Last active: Feb 28 2013 11:49 PM
  • Joined: 02 Nov 2007
alright... I have modified my code with some debugging statements so I can capture a line by line on what is happening on this remote vista machine.

Here's the code I am using:
LoadIEDone(URL_TO_LOAD)
{
fileAppend, in function LOADIE`n, %A_Desktop%\debug.txt
CoInitialize()
fileAppend, coinint done`n, %A_Desktop%\debug.txt
pie := ActiveXObject("InternetExplorer.Application")
fileAppend, pie done `,%pie%`,`n, %A_Desktop%\debug.txt
Invoke(pie, "Visible=", "True")
fileAppend, invoke vis pie done `,%pie%`,`n, %A_Desktop%\debug.txt
Invoke(pie, "Navigate", URL_TO_LOAD)
fileAppend, invoke nav pie done `,%pie%`,`n, %A_Desktop%\debug.txt
Loop
{	
fileAppend, loop %A_Index%`n, %A_Desktop%\debug.txt
   If   Invoke(pie, "ReadyState") = 4
   {
	fileAppend, breaking loop`n, %A_Desktop%\debug.txt
	Break
   }
   Sleep,   500
}

Release(pie)
fileAppend, pie released`n, %A_Desktop%\debug.txt
CoUninitialize()
fileAppend, CoUninitialize() done`n, %A_Desktop%\debug.txt
return pie
}

As you can see I have added a fileappend to an error.txt bwtewwn each line. I have found that on my XP SP2 machine it works fine but on my freind's vista machine it will get stuck in the loop.

Here's the contents of my "debug.txt"
in function LOADIE
coinint done
pie done ,39385724,
invoke vis pie done ,39385724,
invoke nav pie done ,39385724,
loop 1
loop 2
loop 3
loop 4
loop 5
loop 6
loop 7
loop 8
loop 9
loop 10
loop 11
loop 12
loop 13
loop 14
loop 15
loop 16
loop 17
loop 18
loop 19
loop 20
loop 21
loop 22
loop 23
loop 24
loop 25
loop 26
loop 27
loop 28
loop 29
loop 30
loop 31
loop 32
loop 33
loop 34
loop 35
loop 36
loop 37
loop 38
loop 39
loop 40
loop 41
loop 42
loop 43
loop 44
loop 45
loop 46
loop 47
loop 48
loop 49
loop 50
loop 51
loop 52
loop 53
loop 54
loop 55
loop 56
loop 57
loop 58
loop 59
loop 60
loop 61
loop 62
loop 63
loop 64
loop 65
loop 66
loop 67
loop 68
loop 69
loop 70
loop 71
loop 72
loop 73
loop 74
loop 75
loop 76
loop 77
loop 78
loop 79
loop 80
loop 81
loop 82
loop 83
loop 84
loop 85
loop 86
loop 87
loop 88
loop 89
loop 90
loop 91
loop 92
loop 93
loop 94
loop 95
loop 96
loop 97
loop 98
loop 99
loop 100
loop 101
loop 102
loop 103
loop 104
loop 105
loop 106
loop 107
loop 108
loop 109
loop 110
loop 111
loop 112
loop 113
loop 114
loop 115
loop 116
loop 117
loop 118
loop 119
loop 120
loop 121
loop 122
loop 123
loop 124
loop 125
loop 126
loop 127
loop 128
loop 129
loop 130
loop 131
loop 132
loop 133
loop 134
loop 135
loop 136
loop 137
loop 138
loop 139
loop 140
loop 141
loop 142
loop 143
loop 144
loop 145
loop 146
loop 147
loop 148
loop 149
loop 150
loop 151
loop 152
loop 153
loop 154
loop 155
loop 156
loop 157
loop 158
loop 159
loop 160
loop 161
loop 162
loop 163
loop 164
loop 165
loop 166
loop 167
loop 168
loop 169
loop 170
loop 171
loop 172
loop 173
loop 174
loop 175
loop 176
loop 177
loop 178
loop 179
loop 180
loop 181
loop 182
loop 183
loop 184
loop 185
loop 186
loop 187
loop 188
loop 189
loop 190
loop 191
loop 192
loop 193
loop 194
loop 195
loop 196
loop 197
loop 198
loop 199
loop 200
loop 201
loop 202
loop 203
loop 204
loop 205
loop 206
loop 207
loop 208
loop 209
loop 210
loop 211
loop 212
loop 213
loop 214
loop 215
loop 216
loop 217
loop 218
loop 219
loop 220
loop 221
loop 222
loop 223
loop 224
loop 225
loop 226
loop 227
loop 228
loop 229
loop 230
loop 231
loop 232
loop 233
loop 234
loop 235
loop 236
loop 237
loop 238
loop 239
loop 240
loop 241
loop 242
loop 243
loop 244
loop 245
loop 246
loop 247
loop 248
loop 249
loop 250
loop 251
loop 252
loop 253
loop 254
loop 255
loop 256
loop 257
loop 258
loop 259
loop 260
loop 261
loop 262
loop 263
loop 264

Anyone know why it would act differently on either machine? Or how to fix the unending loop?

Joy2DWorld
  • Members
  • 562 posts
  • Last active: Jun 30 2014 07:48 PM
  • Joined: 04 Dec 2006
Loop [color=red]20[/color]

{

Joyce Jamce

ahklerner
  • Members
  • 1386 posts
  • Last active: Oct 08 2014 10:29 AM
  • Joined: 26 Jun 2006
for me
Invoke(pie, "ReadyState")
is always returning '0'.
Vista Home Premium.
Posted Image
ʞɔпɟ əɥʇ ʇɐɥʍ

Erittaf
  • Members
  • 192 posts
  • Last active: Feb 28 2013 11:49 PM
  • Joined: 02 Nov 2007
yeah, it seems that something is wrong there... It returns 4 on my XP SP2 machine just fine, but the vista box I am forced to work with doesn't return 4... ever.

@Joy2DWorld loop 20 defeats the purpose of the entire function.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
On my Vista Business system it opens two windows: one that is eternally "Connecting..." and one that actually loads the page. My guess is 'pie' refers to the one that is eternally connecting, since commenting out Visible= prevents it from showing.

You may have more success starting iexplore.exe, retrieving the WebBrowser of the window, and invoking Navigate() on it.

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007
I've never accessed Vista, so I don't have an idea at all about this. Judging from lexikos said, I only have one suggestion to modify "Navigate" as
Invoke(pie, "Navigate", URL_TO_LOAD, 0)
and/or replace Navigate with Navigate2.
If not work, you have to retrieve the WebBrowser control of the interested page.

ahklerner
  • Members
  • 1386 posts
  • Last active: Oct 08 2014 10:29 AM
  • Joined: 26 Jun 2006
The ready state function is failing.
Posted Image
ʞɔпɟ əɥʇ ʇɐɥʍ

Erittaf
  • Members
  • 192 posts
  • Last active: Feb 28 2013 11:49 PM
  • Joined: 02 Nov 2007
Yes I can confirm that this generates double IE windows. Also the "ready State" is failing... I can play around with code all day long and never know when it'll work on vista.

Vista AHKer's!! please help me out on this one!

Sean
  • Members
  • 2462 posts
  • Last active: Feb 07 2012 04:00 AM
  • Joined: 12 Feb 2007
I'm not sure if it's a feature or a bug of (IE in) Vista. You may replace the ReadyState loop with the following:
Loop
	If	pdoc:=Invoke(pie, "Document")
		  Break
	Else Sleep 100
Loop
	If	Invoke(pdoc, "readyState") = "complete"
		  Break
	Else Sleep 500
Release(pdoc)

Or, I suggest to run the following script after triggering Navigate to see what's running:
<!-- m -->http://www.autohotke...topic19255.html<!-- m -->