By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,351 Members | 1,239 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,351 IT Pros & Developers. It's quick & easy.

COM automation, Internet Explorer, DocumentComplete event

P: n/a
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.

Jan 10 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
puff wrote:
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/05960...0-sect-15.html

Graham

Jan 10 '06 #2

P: n/a
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?

Jan 10 '06 #3

P: n/a
PythonCom interfaces implement __cmp__ so that you can just use
a straight == comparison.

hth
Roger

"puff" <rb********@earthlink.net> wrote in message news:11**********************@g14g2000cwa.googlegr oups.com...
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.



----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
Jan 10 '06 #4

P: n/a
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.

Jan 10 '06 #5

P: n/a
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

Jan 13 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.