how to recognize IE window already opened using win32com extension
Mike Driscoll
kyosohma at gmail.com
Mon Jul 7 12:19:15 EDT 2008
On Jul 7, 11:09 am, korean_dave <davidrey... at gmail.com> wrote:
> 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
-------------------
Mike Driscoll
Blog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org
More information about the Python-list
mailing list