how to recognize IE window already opened using win32com extension

K

korean_dave

How do I use the win32com API to manipulate IE windows ALREADY open?

ie = Dispatch("InternetExplorer.Application") opens a new window.

But I'd like to be able to find, of windows already open, a specific
window (with a specified property, matching url, etc.)
 
T

Tim Golden

korean_dave said:
How do I use the win32com API to manipulate IE windows ALREADY open?

ie = Dispatch("InternetExplorer.Application") opens a new window.

But I'd like to be able to find, of windows already open, a specific
window (with a specified property, matching url, etc.)

I have this strange feeling of deja vu. Is there some sort of
"opening IE windows with Python" conference going on
somewhere?

Have a look at Roger Upole's answer from the other day:

http://mail.python.org/pipermail/python-win32/2008-June/007796.html

TJG
 
M

Mike Driscoll

How do I use the win32com API to manipulate IE windows ALREADY open?

ie = Dispatch("InternetExplorer.Application") opens a new window.

But I'd like to be able to find, of windows already open, a specific
window (with a specified property, matching url, etc.)

You'll probably want to re-post to the PyWin32 user's group, but in
the mean time, here's one way to go about it. I use the following
function:

<code>
def windowEnumerationHandler(self, hwnd, resultList):
'''
This is a handler to be passed to win32gui.EnumWindows() to
generate
a list of (window handle, window text) tuples.
'''

resultList.append((hwnd, win32gui.GetWindowText(hwnd)))
</code>

And call it like this:

<code>
topWindows = []
win32gui.EnumWindows(self.windowEnumerationHandler, topWindows)
</code>

Then you can use a for loop to iterate over the topWindows list to
find the one with the correct title:

<code>
for i in topWindows:
if windowText in i[1]:
# do something
</code>

Notice that I use the win32gui module. Make sure you have the win32
modules installed or this won't work.

Here's the link to PyWin32 group: http://mail.python.org/mailman/listinfo/python-win32

That should get you going...hopefully
 

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

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top