Help me. How to open a new IE window?
calfdog at yahoo.com
calfdog at yahoo.com
Tue May 25 08:50:25 EDT 2004
"Dave Brueck" <dave at pythonapocrypha.com> wrote in message news:<mailman.366.1084046682.25742.python-list at python.org>...
> Vladimir wrote:
> > angel wrote:
> > > I want python(win32com) to open a new IE window.
> > > Source is:
> > > /******/
> > > import win32com.client
> > > msie = win32com.client.Dispatch("InternetExplorer.Application")
> > > msie.Visible = 1
> > > msie.Naviagte(http://www.python.org)
> > > /******/
> > > The problem is the program always grabs a existed IExplorer window or
> > > Explorer window. It never opens a new window.
> >
> > import webbrowser
> > webbrowser.open_new("www.python.org")
> >
> > it will work fine with IE (if IE is the default browser)
>
> I guess the OP didn't specify, but the above won't work if you need to control
> the browser from then on (which is what I assume he was trying to do by
> obtaining an IDispatch pointer to it).
>
> -Dave
Here is how you do it:
Here is a quick way to do it but it works!
If you want to learn more go to pamie.sourceforge.net
This has a class file that helps you automate I.E.
# DispatchEX allows you to open a new window
from win32com.client import DispatchEx
import time
def wait(ie): # very important!!! you have to wait for each page to load
"Given an IE object, wait until the object is ready for input."
while ie.Busy: time.sleep(0.1)
doc = ie.Document
while doc.ReadyState != 'complete': time.sleep(0.1)
return doc
def ClickLink(ie, mylink):
#hrefs = []
for link in ie.Document.links:
if link is None: break # needed for browser bug
if link.innerText == mylink:
link.Click()
# Here is what you need
ie = DispatchEx('InternetExplorer.Application')
ie.Visible = 1
ie.Navigate ('www.python.org')
# Some extra
wait(ie)# Very Important!
ClickLink(ie,'Search')
#later
#RLM
More information about the Python-list
mailing list