[python-win32] Controlling IE file input boxes

Paul_S_Johnson at mnb.uscourts.gov Paul_S_Johnson at mnb.uscourts.gov
Tue Aug 17 18:13:14 CEST 2004


Thanks for the tip Vernon.  It plays very nicely with the win32 module. 
Just set the focus on the form element you want to control before sending 
the input text.

Here's what worked for me. It's painless:
=========================

from win32com.client import DispatchEx
import WindPySend as W

ie = DispatchEx('InternetExplorer.Application')
ie.Navigate("file://C:/myhtml.html")
ie.Visible = 1

myfilebox = ie.Document.forms[0].elements.all["file_1"]
myfilebox.focus()
W.send("C:\mydir\myfile.txt")

Paul S. Johnson

Vernon Cole <> wrote on 08/17/2004 09:36:39 AM:

> Check out  http://users.swing.be/wintclsend/windpysend/ . 
> Windpysend is a package which will emulate typing and/or mouse 
> clicks on another window. Vincent (the author) charges a modest 
> license fee for this. I am hoping that someone will make a good 
> donation to him so that he will release the source. It is a very 
> handy function for a scripting language to have.
> ----------
> Vernon
> 
> -----Original Message-----
> From:Paul S. Johnson [mailto:]
> Sent: Tuesday, August 17, 2004 7:33 AM
> To: python-win32 at python.org
> Cc: Ludovic Reenaers
> Subject: Re: [python-win32] Controlling IE file input boxes

> 
> "Ludovic Reenaers" wrote on 08/17/2004 02:52:07 AM:
> 
> > MAy be try this:
> > from win32com.client import DispatchEx
> > 
> > ie = DispatchEx('InternetExplorer.Application')
> > ie.Navigate("file://C:/myhtml.html")
> > ie.Visible = 1
> > myfilebox = ie.Document.forms[0].elements.all["file_1"]
> > [myfilebox.Value='c:\\xx\\xx.txt']  OR 
[myfilebox.Value('c:\\xx\\xx.txt')]
> > It should be possible that kind of way.
> > 
> > Ludo
> 
> I wish it was as simple as that. For INPUT tags of where type=FILE, 
> the Value attribute is read-only. I can fetch a value that was 
> manually input by the user, but I cannot set it. This, I suppose, is
> for security reasons so evil web programmers cannot go phishing for 
> files on the user's hard drive. 
> 
> > 
> >  We are testing a web site we are developing by controlling IE through
> > > Python and need to be able to input the value of an INPUT tag where
> > > TYPE=FILE.  I understand the security concern of MS not 
allowingthis, but
> > > isn't there some way around it?  The python code below initiates the
> > > windows file dialog (what happens when someone clicks the "browse" 
button
> > > of the file input box).  Is there anyway to script through this and 
input
> > > a file name?
> > >
> > > ===============================
> > > HTML:
> > >
> > > <html>
> > >   <head>
> > >     <title>My Site</title>
> > >   </head>
> > >   <body>
> > >     <form name="myform" action="" method="post">
> > >       <input type="file" name="file_1" value="Pick Me"><br>
> > >     </form>
> > >   </body>
> > > </html>
> > > ===============================
> > > Python code:
> > >
> > > from win32com.client import DispatchEx
> > >
> > > ie = DispatchEx('InternetExplorer.Application')
> > > ie.Navigate("file://C:/myhtml.html")
> > > ie.Visible = 1
> > > myfilebox = ie.Document.forms[0].elements.all["file_1"]
> > > myfilebox.click()
> > > #??? now what???
> > > ================================
> > >
> > > Paul Johnson
> > > _______________________________________________
> > > Python-win32 mailing list
> > > Python-win32 at python.org
> > > http://mail.python.org/mailman/listinfo/python-win32
> > >
> > 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20040817/c8fb980f/attachment.html


More information about the Python-win32 mailing list