COM automation, Internet Explorer, DocumentComplete event

P

puff

I'm very new to Python and have a question concerning IE automation and
detection of page completion.

The MSDN article 180366 states in part:

----
The top-level frame fires the DocumentComplete in the end. So, to check
if a page is done downloading, you need to check if the IDispatch*
parameter is same as the IDispatch of the WebBrowser control.

For Visual Basic, here is code that performs this check:

Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object,
URL As Variant)
If (pDisp Is WebBrowser1.Object) Then
Debug.Print "Web document is finished downloading"
End If
End Sub
----

I'm able to catch IE's events including DocumentComplete with:

def OnDocumentComplete(self, pDisp, URL):

so i have pDisp. Self is the object returned by:

self.ie = DispatchWithEvents("InternetExplorer.Application",
InternetExplorerEvents)

that created the automation object. How do I perform the test in
Python?

Thanks for any help.
 
G

Graham Fawcett

puff said:
I'm able to catch IE's events including DocumentComplete with:

def OnDocumentComplete(self, pDisp, URL):

so i have pDisp. Self is the object returned by:

self.ie = DispatchWithEvents("InternetExplorer.Application",
InternetExplorerEvents)

that created the automation object. How do I perform the test in
Python?

This recipe might give you some clues; you can use the Busy attribute,
instead of a DocumentComplete handler:

http://herlock.com/ob/pythoncb/0596007973/chp-10-sect-15.html

Graham
 
P

puff

Without going into an overly long discussion, suffice to say that the
busy attribute, notwithstanding Microsoft documentation to the
contrary, simply doesn't work.

BTW, there are a fair number of URLs for which PAMIE's combination of
busy and readystate doesn't work.

This scheme is somewhat better than both, but (of course it could only
be) also doesn't work under some cases. Nevertheless, it's better
than depending on busy or ready state.

So how do I do the equivalent of pDisp Is WebBrowser1.Object in python?
 
R

Roger Upole

PythonCom interfaces implement __cmp__ so that you can just use
a straight == comparison.

hth
Roger
 
P

puff

Thanks very much Roger.

As you might have guessed, I'm rather new to Python. The notion that
== does the job illustrates one of the reason's I've undertaken
learning yet another new language (40+ years on, the language count is
rather larger than I'd care to admit). I should also mention the
fact that a newsgroup post actually gets an answer is a big plus.
Thanks again.

I was in a bit of a rush in my post about busy. Let me take a minute
to explain on the off chance that someone else might benefit.

IE's busy attribute doesn't work for determining when a page has
fully downloaded. It only indicates IE's internal work state. If you
watch the event stream, busy, and readystate while pages are loading
you often see busy go false and then go true again fairly quickly. So,
busy as a reliable check for page completely loaded is a fairly poor
choice.

I mentioned PAMIE. It uses a technique that waits for busy false, then
readystate complete. This is much better than simple busy, but suffers
from two flaws. First the last time I looked at that PAMIE's code
the checks were serial. So it can get confused by an early busy false,
then go into it's readystate complete check inappropriately early.
This aside, there are pages where during loading, busy is false and
ready state complete for a short time then more page content is
downloaded (watching the event stream from real world pages is a very
informative experience when it comes to a page being complete).

The technique suggested in the MS KB article, actually works fairly
well for determining when the page is in fact fully downloaded as a
result of the thing that started the navigation (lots of things other
than navigate can cause navigations, BTW). It basically means that the
browser has all the bytes associated with the page in hand.
Unfortunately, it also fails (although rather less often than any
technique involving either busy or readystate) when the page has script
that mucks about with the DOM, causes additional activity over the web,
etc.

Thanks again.
 
C

calfdog

R. Bell,

If you could sent me those URLS that are not working with PAMIE it
would be great.
It should be a quick fix. I haven't had any of the Users report this as
of yet.

I notice your writing an app that automates IE also, best of luck with
it!!


Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top