Jump to content

Setting the value for input type="file"


Recommended Posts

I can't get it to write into the input field is there any way to do this?

The html:

<html>
<body>
<form action="upload_file.php" method="post"
enctype="multipart/form-data" name="ding">
<input type="file" name="file" id="file" value=""/> 
<br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>

The autoit:

$oIE=_IECreate("http://www.removed.com/g.html", 0, 1, 1)
$oForm = _IEFormGetObjByName ($oIE, "ding")
$file = _IEFormElementGetObjByName ($oForm, "file")
$submit = _IEFormElementGetObjByName ($oForm, "submit")
_IEFormElementSetValue($file, '"C:\log.txt"')
;code above doesn't set a value
_IEAction($submit, "click")
Link to comment
Share on other sites

did you put the #include<IE.au3> at the begining of script ?

[quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys

Link to comment
Share on other sites

Please read the message printed to the SciTe console when you try that and look at the Remarks for the _IEFormElementSetValue command in the helpfile.

I tried really hard to help you, but you gotta read :)

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Please read the message printed to the SciTe console when you try that and look at the Remarks for the _IEFormElementSetValue command in the helpfile.

I tried really hard to help you, but you gotta read :)

Dale

:) by the way, can you give me a help here :

http://www.autoitscript.com/forum/index.php?showtopic=67986

[quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys

Link to comment
Share on other sites

Yes, I replied to that post and I must repeat:

I tried really hard to help you, but you gotta read :)

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

did you put the #include<IE.au3> at the begining of script ?

Yes, that's just the snippet in question.

Please read the message printed to the SciTe console when you try that and look at the Remarks for the _IEFormElementSetValue command in the helpfile.

I tried really hard to help you, but you gotta read :)

Dale

Not getting an error message.

>Running:(3.2.0.1):C:\Programme\AutoIt3\autoit3.exe "C:\Dokumente und Einstellungen\Kevin\Desktop\Scripts\upload.au3"   
+>AutoIT3.exe ended.rc:0
>Exit code: 0   Time: 9.988

What do you mean? The helpfile says that the file attribute should work.

While all Form Elements have a value, only text oriented elements use their value attribute in an obvious fashion (type text, textarea, hidden, password and file).

Link to comment
Share on other sites

What do you mean? The helpfile says that the file attribute should work.

Straight from the help file:

Note: You cannot use _IEFormElementSetValue to set the value of an INPUT TYPE=FILE element. Browser security restrictions prevent this element from being scripted. See the example below for a workaround.

..and for the example:

; *******************************************************
; Example 4 - Set the value of an INPUT TYPE=FILE element
;               (security restrictions prevent using _IEFormElementSetValue)
; *******************************************************
;
#include <IE.au3>

$oIE = _IE_Example("form")
$oForm = _IEFormGetObjByName($oIE, "ExampleForm")
$oInputFile = _IEFormElementGetObjByName($oForm, "fileExample")

; Assign input focus to the field and then send the text string
_IEAction($oInputFile, "focus")
Send("C:\myfile.txt")

As Dale said...you must read!

Link to comment
Share on other sites

Straight from the help file:

..and for the example:

; *******************************************************
; Example 4 - Set the value of an INPUT TYPE=FILE element
;               (security restrictions prevent using _IEFormElementSetValue)
; *******************************************************
;
#include <IE.au3>

$oIE = _IE_Example("form")
$oForm = _IEFormGetObjByName($oIE, "ExampleForm")
$oInputFile = _IEFormElementGetObjByName($oForm, "fileExample")

; Assign input focus to the field and then send the text string
_IEAction($oInputFile, "focus")
Send("C:\myfile.txt")

As Dale said...you must read!

I can't read something that doesn't exist in my helpfile, guess it's outdated.

Thanks for the workaround, much appreciated.

Link to comment
Share on other sites

  • 2 weeks later...

Well, I needed to do something very similar, the code is posted below.

The problem I have with it, is that even when you steal from the docs, and use '_IEAction($oIE, "invisible")', it's not _truly_ invisible. It pops up for a second, then it vanishes.

I can't get this code to work with _IECreateEmbedded, I'm guessing that's due to:

There are several properties related to an InternetExplorer object (e.g. returned by _IECreate) that do not apply to this object. These include status text, addressbar and others that may exist for a browser, but do not exist for an embedded control.

Granted, that's a bit vague, so I'm not really sure. Does anybody have any suggestions for making this happen in the background, without any windows flashing in front of the user?

#include <IE.au3>; browser
$path = 'c:\log.txt'
$url = 'http://www.removed.com/g.html'

; CREATE BROWSER
$oIE = _IECreate($url)

; get the form
$oForm = _IEFormGetObjByName($oIE, 'ding')

; get the file input box.
$file = _IEFormElementGetObjByName($oForm, "file")

; get the 'handle' (hwnd) for the IE window.
$hIE = _IEPropertyGet($oIE, "hwnd"); 

; Assign input focus to the field and then send the text string
_IEAction($file, "focus")
ControlSend($hIE, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", $path)

_IEFormSubmit($oForm)
Link to comment
Share on other sites

Yeah, my thoughts are 1) don't pile onto someone else's closed thread and 2) _IECreateEmbedded has nothing to do with the test of your post.

Please ask a more specific question in your own thread.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Yeah, my thoughts are 1) don't pile onto someone else's closed thread and 2) _IECreateEmbedded has nothing to do with the test of your post.

Please ask a more specific question in your own thread.

Dale

How is it 'closed'? It's not even 2 weeks old. I could understand that if it was a year old, or even a month. I can dig the fact that Das Ami was driving you nuts, but don't take that frustration out on me.

It seemed like an appropriate place to put it. I found this thread while searching for the same question - how to submit a file upload form. This thread was helpful, but didn't actually contain an example. I added it here, figuring others would find it the same way I did (and would appreciate the example).

I didn't post the IECreateEmbedded example because it didn't work, and I deleted it. If you want to see that code, I'll put it back together. The problem with it was that _IEFormGetObjByName and _IEFormElementGetObjByName weren't returning anything in an embedded browser.

I did ask a specific question: "Does anybody have any suggestions for making this happen in the background, without any windows flashing in front of the user?"

Is there some magical way to truly hide an _IECreate object, or can somebody show me a working example with IECreateEmbedded?

You can answer the question, ignore the post, or play forum cop. That last one isn't very helpful though.

ps: nice avatar (seriously).

Link to comment
Share on other sites

Argue if you want, but if you would like some help from me you'll heed the advice.

Dale

Edited by DaleHohm

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

The only might I'm wielding is my assistance. The choice is yours.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...