mgeorg Posted July 21, 2012 Share Posted July 21, 2012 Hi everybody, I'm trying to automate uploading files via a internet explorer form. To do that I click the field where you can enter the path to the file with _IEAction($fileField, "click") which actually opens a window, where I can manually select the file to upload. However it blocks the further execution of my code. It would be great is someone here could tell me, how I can load the "upload file" window from IE without blocking further execution or give me a hint about some other way, to upload a file via internet explorer form. (Other ways of file upload are not possible in my environment, because of security issues.) Thanks in advance, - Michael Link to comment Share on other sites More sharing options...
bogQ Posted July 21, 2012 Share Posted July 21, 2012 (edited) as far as i remamber automating type='file' will not work with _IE coz ie8+ are construtced not to support something like that (upload spam-viruses and something similar wos the reason) Edited July 21, 2012 by bogQ TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
mgeorg Posted July 21, 2012 Author Share Posted July 21, 2012 Hello bogQ,thanks for your feedback. Wouldn't it be possible to introduce some kind of parallelism into the script to, e.g. with ChildProc.au3 (see ) to handle the popup window, even so the main program flow is blocked?Sadly, yet I don't really understand how that ChildProc is working. - Michael Link to comment Share on other sites More sharing options...
mgeorg Posted July 22, 2012 Author Share Posted July 22, 2012 (edited) Using a separate thread to handle the upload window was indeed successful. Following code enables automated upload of a file at $fullFilePath (at least for german windows - for english you would need to replace "Datei zum hochladen auswählen" by the english title of the upload window. ;new thread to handle upload window after blocking browse call $uploadWindowThreadStart = DllCallbackRegister('AdditionalUploadWindowThread', 'int', 'ptr') If $uploadWindowThreadStart == 0 Then MsgBox(0x10, "Error", "DllCallbackRegister failed") Exit EndIf Func AdditionalUploadWindowThread($void) While True $uploadWindowHandle = WinGetHandle("Datei zum Hochladen auswählen") If ($uploadWindowHandle = 0) Then Sleep(1500) Else ControlSend($uploadWindowHandle, "", "[CLASS:Edit; INSTANCE:1]", $fullFilePath) ControlClick($uploadWindowHandle, "", "[CLASS:Button; INSTANCE:2]") ExitLoop EndIf WEnd EndFunc ;start thread that handles file upload popup and press browse button DllCall("kernel32.dll", "hwnd", "CreateThread", "ptr", 0, "dword", 0, "long", DllCallbackGetPtr($uploadWindowThreadStart), "ptr", 0, "long", 0, "int*", 0) _IEAction($fileField, "click") Edited July 22, 2012 by mgeorg Link to comment Share on other sites More sharing options...
DaleHohm Posted July 23, 2012 Share Posted July 23, 2012 See also, workarounds in my sig that use ControlSend. 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 More sharing options...
mgeorg Posted July 23, 2012 Author Share Posted July 23, 2012 Hi Dale, thank you, I guess your solution is much better than mine, because you don't need a separate thread this way. Anyway, to get the solution with a separate thread running stable, I needed to remove the while loop from the additional thread and instead using the following code: Func AdditionalUploadWindowThread($void) $uploadWindowHandle = WinGetHandle("Datei zum Hochladen auswählen") If ($uploadWindowHandle <> "") Then ConsoleWrite("got handle for upload window" & @CRLF) ControlSend($uploadWindowHandle, "", "[CLASS:Edit; INSTANCE:1]", $fullFilePath) ControlClick($uploadWindowHandle, "", "[CLASS:Button; INSTANCE:2]") Else Sleep(1000) $uploadWindowHandle = WinGetHandle("Datei zum Hochladen auswählen") If ($uploadWindowHandle <> "") Then ControlSend($uploadWindowHandle, "", "[CLASS:Edit; INSTANCE:1]", $fullFilePath) ControlClick($uploadWindowHandle, "", "[CLASS:Button; INSTANCE:2]") EndIf EndIf EndFunc Can anyone in here explain to me, why the program gets stuck sometimes, if I use a while loop with a sleep command instead of executing the same commands again in the else path? - Michael Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now