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

maybe to keep *all* functions tied to the library. ie. HEX() to acc_hex() ...

OK, I updated ACC.ahk.

How to turn the document object handle into handle that can be bound COM_events ?

I'm not sure what you mean, it's already connectible. Would you be more specific?

Joy2DWorld
  • Members
  • 562 posts
  • Last active: Jun 30 2014 07:48 PM
  • Joined: 04 Dec 2006

Would you be more specific?


@Sean, you've moved with such huge advances the reaches of what AHK is able to do... that sometimes my mind goes fuzzy figuring out all that ground!!

more specifically: How do get the same result that COM_ConnectObject(pie , "Web_") gives us eg. Web_BeforeNavigate2(prms), but with a DOM object event (doc, window, or whatever). For sake of example: onbeforecopy .


ie. something like getref()
<!-- m -->http://msdn2.microso...y/ekabbe10.aspx<!-- m -->
Joyce Jamce

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

more specifically: How do get the same result that COM_ConnectObject(pie , "Web_") gives us eg. Web_BeforeNavigate2(prms), but with a DOM object event (doc, window, or whatever).

I don't know if DOM provides means to cancel the navigation, I'm a bit skeptical about it. You have to read the documentation in MSDN for it.

BTW, you can use the event of WebBrowser control for it, if you find none.

#Persistent
MouseGetPos,,,, hIESvr, 2
OnExit,	AccClose

ACC_Init()
IID_IHTMLWindow2   := "{332C4427-26CB-11D0-B483-00C04FD90119}"
IID_IWebBrowserApp := "{0002DF05-0000-0000-C000-000000000046}"
pacc := ACC_AccessibleObjectFromWindow(hIESvr)
pwin := COM_QueryService(pacc,IID_IHTMLWindow2,IID_IHTMLWindow2)
pweb := COM_QueryService(pwin,IID_IWebBrowserApp,IID_IWebBrowserApp)
psink:= COM_ConnectObject(pweb, "Web_")
Return

AccClose:
COM_Release(psink)
COM_Release(pweb)
COM_Release(pwin)
COM_Release(pacc)
ACC_Term()
ExitApp

Web_BeforeNavigate2(prms, this)
{
	If	COM_DispGetParam(prms, 1) = "http://www.autohotkey.com/"
		NumPut(-1, NumGet(NumGet(prms+0)+8), 0, "short")   ; cancel the navigation
}


Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

more specifically: How do get the same result that COM_ConnectObject(pie , "Web_") gives us ... but with a DOM object event (doc, window, or whatever). For sake of example: onbeforecopy .

I'm not sure what you mean, it's already connectible.

I have used
COM_ConnectObject(el, "Win_")
where el is a pointer to an element object / HTML/DOM element.

ie. something like getref()

In context:
Set object.eventname = GetRef(procname)
My understanding of this is:
[*:1m14pek8]GetRef(procname) builds an object (implementing IDispatch) wrapping procname().
[*:1m14pek8]The IDispatch object is assigned to the 'eventname' property.
[*:1m14pek8]When the event occurs, the default method of the IDispatch object is called, which in turn calls procname().To do this in AutoHotkey, we need to build our own object implementing IDispatch. Fortunately, ConnectObject() already does this, so we can adapt ConnectObject, CreateIDispatch and DispInterface.

I've just posted an example in the COM Event Handler thread (seems more appropriate.)

Joy2DWorld
  • Members
  • 562 posts
  • Last active: Jun 30 2014 07:48 PM
  • Joined: 04 Dec 2006
@Sean,

Flawless.


@lexikos,

I have used

COM_ConnectObject(el, "Win_")
where el is a pointer to an element object / HTML/DOM element.



could you give an example of callback function (ie. function name) that's work with... [am streching my brain to try to keep pace with you'all!!!]
Joyce Jamce

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
Win_onscroll()

Joy2DWorld
  • Members
  • 562 posts
  • Last active: Jun 30 2014 07:48 PM
  • Joined: 04 Dec 2006
@lexikos,

wow. ok, am starting to catch on... thanks!!


and, more and more realizing the incredible power/simplicity in use of what Sean has done with the Invoke()... incredible.
Joyce Jamce

Guest1213
  • Guests
  • Last active:
  • Joined: --
Ya why not put it into a command in AHK software.

hotzenpl0tz
  • Members
  • 11 posts
  • Last active: Apr 17 2008 08:02 PM
  • Joined: 22 Oct 2007
Could someone give me a pointer, what I would have to look at, to make this work for the active internet explorer window ?

I have the following problem, that I have to deal with pretty often:

a) I have to open up a webpage, wait for it to load, then navigate to the login part of the webpage, and login.

B) Now I have to navigate to a certain link, that opens another internet explorer window. Now again, I have to wait until it is loaded until I can continue with my automation tasks.

For "a)" I can deal with, with the proposed solutions in here. Now I need something to work with "b)" - what would be great, would be a way to determine if the webbrowser has started to load the webpage, then wait until it is loaded (with the same methods posted here I suppose) and then continue.
The problem is, that I can't just fire of the script to wait for load, after the new internet explorer window has opened, because I have to wait for it to start loading the webpage first, otherwise the script won't work. Is there a way to do that, maybe with that COM stuff ?

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

The problem is, that I can't just fire of the script to wait for load, after the new internet explorer window has opened, because I have to wait for it to start loading the webpage first, otherwise the script won't work. Is there a way to do that, maybe with that COM stuff ?

You may read it:
<!-- m -->http://www.autohotke...ic19256-15.html<!-- m -->

hotzenpl0tz
  • Members
  • 11 posts
  • Last active: Apr 17 2008 08:02 PM
  • Joined: 22 Oct 2007
Hm thanks, but I have to admit that I couldn't find the part relevant to my problem. I saw the following code you suggested:

#Include CoHelper.ahk 
F12:: 
CoInitialize() 
pie := ActiveXObject("InternetExplorer.Application") 
Invoke(pie, "Visible=", "True") 
Invoke(pie, "Navigate", "http://maps.google.ca/maps?ie=UTF-8&oe=UTF-8&hl=en&tab=wl&q=") 
Loop 
{ 
   If   Invoke(pie, "ReadyState") = 4 
      Break 
   Sleep,   500 
} 
Release(pie) 
CoUninitialize() 
Run,   calc.exe 
Return 

Now this works great, to open up a new page and navigate to it, but I don't know how to modify it, so it works with an explorer instance that gets opened by clicking on a link on a webpage by javascript or such. Now if that is answered in one of your later posts (I read through them all, but it's very possible that I didn't get it, I am not that fluent with COM, DOM etc.), I would be greatfull if you could point me to the correct post. If not, maybe you could post a small example code snippet, if there is a way to write a "loop" statement, that wats for the "Internet Explorer_Server control" to be available, and then continues on with the Waitforload Script. Thanks alot in advance, and sorry for wasting your time ;)

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

I don't know how to modify it, so it works with an explorer instance that gets opened by clicking on a link on a webpage by javascript or such.

Sean demonstrated further up this page (page 3) how to get the WebBrowser object (pweb) of a running instance of Internet Explorer. WebBrowser and InternetExplorer have most (if not all) of the same properties and methods.

To get a different (from the example) instance of IE, change
MouseGetPos,,,, hIESvr, 2
to
ControlGet, hIESvr, Hwnd,, Internet Explorer_Server1, [color=olive]ahk_class IEFrame[/color]  ; or whatever WinTitle


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

Sean demonstrated further up this page (page 3) how to get the WebBrowser object (pweb) of a running instance of Internet Explorer.

Just in case, this technique can be used with any DOM objects, not only with Window object, as far as I tested. So, if don't like to use ACC.ahk, may do it with the code in the first post of this thread by adding:
pweb := COM_QueryService(pdoc,IID_IWebBrowserApp,IID_IWebBrowserApp)

so it works with an explorer instance that gets opened by clicking on a link on a webpage by javascript or such.

I'm not sure of exactly what you have in mind. If what lexicos suggested is what you wanted, you may ignore the following.
Here is one example, which will always open a new window for the page you clicked in the first/original start-up IE window, and waits for it completely loaded and then pop up message box.

#Persistent
OnExit, CleanUp

COM_CoInitialize()
pweb := COM_CreateObject("InternetExplorer.Application")
COM_Invoke(pweb, "Visible=", "True")
COM_Invoke(pweb, "Navigate", "http://www.autohotkey.com/forum/")
ReadyState(pweb)
MsgBox, Ready
COM_ConnectObject(pweb, "Web_")
Return

CleanUp:
COM_Release(pweb)
COM_CoUninitialize()
ExitApp


Web_BeforeNavigate2(prms, this)
{
	NumPut(-1, NumGet(NumGet(prms+0)+8), 0, "short")	; cancel the navigation
	pweb := COM_CreateObject("InternetExplorer.Application")
	COM_Invoke(pweb, "Visible=", "True")
	COM_Invoke(pweb, "Navigate", COM_DispGetParam(prms, 1))
	ReadyState(pweb)
	COM_Release(pweb)
	MsgBox, Ready
}

ReadyState(pweb)
{
	Loop
		If	COM_Invoke(pweb, "ReadyState") <> 4
			Sleep,   500
		Else	Break
}


hotzenpl0tz
  • Members
  • 11 posts
  • Last active: Apr 17 2008 08:02 PM
  • Joined: 22 Oct 2007
Thanks you two, your comments brought me a few steps forward, although I will need some time to get a hang of the COM stuff. Until now, I tried to automate some tasks I had to do with a webbrowser by using the old "done in statusbar" method, but that was just plain unreliable.

For what it's worth, the following describes what I am attempting to do - because I think it is probable that somebody will have to do something similar someday, and I will post the most important parts of my solution, should I get it working reliably:

At work, we have a big database of Computers, Users, Telephone numbers, Login Information etc. This database used to be an MS Access Database localy in our department, that we could access with VBScript or something similar to get the needed information and automate some repetitive tasks (insert data into an excel sheet for example). The system was now changed - the database is now only accessible with a webinterface and I have to do some insane HTML Sourcecode parsing to get the desired information. Now the problem isn't the parsing but the way I have to go to get it: I need to open an internet explorer instance, login to the webpage, then navigate to the search button, press that button - now a second internet explorer instance opens with the search field, I then input the pc login name I am looking for. When that search finishes, the internet explorer instance in the background (the first instance) changes to the search result, and from there on I have to go on, get the source and do my parsing. As you may guess, this involves ALOT of timing issues - and those appear in 2 different internet explorer instances, so this is getting pretty confusing.

Nevertheless, I think some of the points you gave me can help me here - I think looking for the events with COM_Connectobject should help me out here. Thanks for the help you have given me, it is greatly appreciated :)

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

pweb := COM_QueryService(pdoc,IID_IWebBrowserApp,IID_IWebBrowserApp)

Shouldn't that be IHTMLDocument or IHTMLDocument2? Actually, I find it easier to do:
pdoc := COM_Invoke(pweb,"Document")