[python-win32] Controlling IE file input boxes

Paul_S_Johnson at mnb.uscourts.gov Paul_S_Johnson at mnb.uscourts.gov
Tue Aug 17 15:32:57 CEST 2004


"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 allowing this, 
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/91fd29e7/attachment.htm


More information about the Python-win32 mailing list