JadeGolem Posted July 9, 2010 Share Posted July 9, 2010 I'm having a problem getting a "file open" box to work. On a web page that allows upload of images they use the following code in their form: File Name: <input type=file name="Attach"><br /> Photo Name: <input type=text name="Label"><br /> With the following code I get the following error from AutoIt: "--> IE.au3 V2.4-0 Error from function _IEFormElementSetValue, $_IEStatus_InvalidObjectType (Browser securuty prevents SetValue of TYPE=FILE)" $filename = "C:\my_path\Sample_Pictures\winter.jpeg" $oIEMain = _IEAttach("Internet") $oIEWork = _IEFrameGetObjByName($oIEMain, "main") ; page uses frames - this gets the right one $oIEForm = _IEGetObjByName($oIEWork, "form1") $oControl = _IEFormElementGetObjByName($oIEForm, "Attach") _IEFormElementSetValue($oControl, $filename) And with this code, I get the dialog box to pop up, but AutoIt can't interact with it (script execution pauses on _IEAction statement until the "Choose File To Upload" window closes - requires user's intervention). $filename = "C:\my_path\Sample_Pictures\winter.jpeg" $oIEMain = _IEAttach("Internet") $oIEWork = _IEFrameGetObjByName($oIEMain, "main") ; page uses frames - this gets the right one $oIEForm = _IEGetObjByName($oIEWork, "form1") $oControl = _IEFormElementGetObjByName($oIEForm, "Attach") _IEAction($oControl, "click") if (Not WinWaitActive("Choose File to Upload", "File &name:", 3)) Then ; Couldn't find file upload window ConsoleWrite("Couldn't find file upload window"&@CRLF) exit EndIf ConsoleWrite("Sending filename"&@CRLF) Send($filename) Does anyone have any idea how to automate populating an input tag of type=file with a filename in IE, or how to turn off the browser security that prevents the setvalue of TYPE=FILE? Using Windows 7 and IE 8. Thanks, Ken Link to comment Share on other sites More sharing options...
Juvigy Posted July 9, 2010 Share Posted July 9, 2010 if (Not WinWaitActive("Choose File to Upload", "File &name:", 3)) Then ; Couldn't find file upload window ConsoleWrite("Couldn't find file upload window"&@CRLF) exit Else Send("C:\filename.xls") EndIf This should work if the focus is on the input. Link to comment Share on other sites More sharing options...
JadeGolem Posted July 9, 2010 Author Share Posted July 9, 2010 if (Not WinWaitActive("Choose File to Upload", "File &name:", 3)) Then ; Couldn't find file upload window ConsoleWrite("Couldn't find file upload window"&@CRLF) exitElse Send("C:\filename.xls")EndIf This should work if the focus is on the input.That's essentially what I've written in my second method of addressing the issue above. The problem is that the "Choose File to Upload" window does indeed have the focus (I've clicked on it while running to be sure), but the script can't run the WinWaitActive line because it's stuck on the _IEAction line that opened the window. For some reason that _IEAction call sits around waiting for the window to close before returning so I get no opportunity to interact with it. Link to comment Share on other sites More sharing options...
Juvigy Posted July 9, 2010 Share Posted July 9, 2010 And if you change: if (Not WinWaitActive("Choose File to Upload", "File &name:", 3)) Then ; Couldn't find file upload window ConsoleWrite("Couldn't find file upload window"&@CRLF) exit Else Send("C:\filename.xls") EndIf To Sleep(2000) Send("C:\filename.xls") does it work? Link to comment Share on other sites More sharing options...
JadeGolem Posted July 9, 2010 Author Share Posted July 9, 2010 And if you change: if (Not WinWaitActive("Choose File to Upload", "File &name:", 3)) Then ; Couldn't find file upload window ConsoleWrite("Couldn't find file upload window"&@CRLF) exit Else Send("C:\filename.xls") EndIf To Sleep(2000) Send("C:\filename.xls") does it work? No, it pauses on the _IEAction call so it never gets to the sleep. For instance if I run $filename = "C:\my_path\Sample_Pictures\winter.jpeg" $oIEMain = _IEAttach("Internet") $oIEWork = _IEFrameGetObjByName($oIEMain, "main") ; page uses frames - this gets the right one $oIEForm = _IEGetObjByName($oIEWork, "form1") $oControl = _IEFormElementGetObjByName($oIEForm, "Attach") _IEAction($oControl, "click") sleep(1000) ConsoleWrite("I at least got past the _IEAction click without help") if (Not WinWaitActive("Choose File to Upload", "File &name:", 3)) Then ; Couldn't find file upload window ConsoleWrite("Couldn't find file upload window"&@CRLF) exit Else sleep(2000) Send("C:\filename.xls") EndIf then the script freezes/pauses with the "Choose File to Upload" dialog open and with focus (I've left it alone for a minute or more), and the ConsoleWrite("I at least got past the _IEAction click without help") never gets written to the console during that minute or so, at least not until I either load a file by hand or hit cancel manually closing the dialog, at which time the "got past _IEAction" ConsoleWrite message finally gets written and the script continues and gives me the ConsoleWrite("Couldn't find file upload window"&@CRLF) message. The script is clearly waiting in an infinite loop for the "Choose File to Upload" dialog to close before returning from the _IEAction call. Link to comment Share on other sites More sharing options...
Juvigy Posted July 9, 2010 Share Posted July 9, 2010 I am guessing there is OK/Cancel buttons and a browse/attach button right ? Did you try to focus the input element and just Send(filename) and after the click the OK or browse/attach buttons ? Link to comment Share on other sites More sharing options...
DaleHohm Posted July 9, 2010 Share Posted July 9, 2010 Here's an example of how to automat this and get around the security restriction: #include <IE.au3> $oIE = _IE_Example("form") $oT = _IEGetObjById($oIE, 'fileExample') MouseMove(_IEPropertyGet($oT, "screenx") + _IEPropertyGet($oT, "width") - 10, _ _IEPropertyGet($oT, "screeny") + _IEPropertyGet($oT, "height")/2) MouseClick("left") WinWait("Choose File to Upload") $hChoose = WinGetHandle("Choose File to Upload") ControlSetText($hChoose, "", "Edit1", "C:\AUTOEXEC.BAT") ControlClick($hChoose, "", "Button2") Dale vick 1 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...
JadeGolem Posted July 10, 2010 Author Share Posted July 10, 2010 Here's an example of how to automat this and get around the security restriction:Thanks Dale - that's exactly what I needed. I had thought of a hack resembling something similar as a last resort, but this cleaner. Link to comment Share on other sites More sharing options...
DaleHohm Posted September 8, 2010 Share Posted September 8, 2010 @wakillon - this reply belongs on another thread. Please add it there and blank out this one. When you do I will reply with some helpful information. 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...
StrangeQuark Posted February 10, 2011 Share Posted February 10, 2011 Here's an example of how to automat this and get around the security restriction: #include <IE.au3> $oIE = _IE_Example("form") $oT = _IEGetObjById($oIE, 'fileExample') MouseMove(_IEPropertyGet($oT, "screenx") + _IEPropertyGet($oT, "width") - 10, _ _IEPropertyGet($oT, "screeny") + _IEPropertyGet($oT, "height")/2) MouseClick("left") WinWait("Choose File to Upload") $hChoose = WinGetHandle("Choose File to Upload") ControlSetText($hChoose, "", "Edit1", "C:\AUTOEXEC.BAT") ControlClick($hChoose, "", "Button2") Dale Can You tell me why $oT.click instead of MouseMove/MouseClick doesn't work ? Selection File window shows,but script is not interacting with it. Link to comment Share on other sites More sharing options...
alex33 Posted August 2, 2015 Share Posted August 2, 2015 My russion Work example: (for russion site rghost, for Windows 7 RUS, IE11) : #include <IE.au3> Global $oIE = _IECreate("http://rghost.ru/") Global $iTimer=TimerInit() $oIE.navigate('javascript:document.getElementById("choose").click();void(0);',0) ConsoleWrite("===time: "&TimerDiff($iTimer)&"==="&@CRLF) ;Beep(900, 1000) Global $sFilePath=@ScriptFullPath Global $hwnd=WinWait("Выбор выкладываемого файла","",5) If Not $hwnd Then Exit 2 ControlSetText($hwnd,"","Edit1",$sFilePath) Sleep(3000); задержка, чтобы было видно ControlClick($hwnd,"","Button1") corgano 1 Link to comment Share on other sites More sharing options...
guinness Posted August 3, 2015 Share Posted August 3, 2015 4 years too late I see, unless you have really slow e-mail?! Anyway the reason a file input cannot be automated is because it's a security vulnerability if it were. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Maintel Posted June 29, 2016 Share Posted June 29, 2016 (edited) This is an old thread, but google will find it when people search about this problem, so here is my solution. Script will hang until "Choose File to Upload" dialog is open, so you can not write any text. Solution to this problem is to create second AutoIt script, you can start and stop it from your main script, or just start it manually. You can pass the path to file via Clipboard, create some Label in GUI, write it to file etc etc. Passing variable from main script $oForm = _IEFormGetObjByName($oIE, "form_ID") ... _ClipBoard_SetData("c:\example.jpg") $oFormSelectFile = _IEFormElementGetObjByName($oForm, "open_file_element_ID") _IEAction($oFormSelectFile, "click") Second script #include <Clipboard.au3> While 1 $handle = WinWait("Choose File to Upload") Sleep(300) $file = _ClipBoard_GetData() ControlSend($handle, '', 'Edit1', $file & '{ENTER}') Sleep(300) WEnd Edited July 27, 2016 by Maintel Link to comment Share on other sites More sharing options...
Toan10921 Posted December 13, 2016 Share Posted December 13, 2016 On 30/6/2016 at 4:33 AM, Maintel said: This is an old thread, but google will find it when people search about this problem, so here is my solution. Script will hang until "Choose File to Upload" dialog is open, so you can not write any text. Solution to this problem is to create second AutoIt script, you can start and stop it from your main script, or just start it manually. You can pass the path to file via Clipboard, create some Label in GUI, write it to file etc etc. Passing variable from main script $oForm = _IEFormGetObjByName($oIE, "form_ID") ... _ClipBoard_SetData("c:\example.jpg") $oFormSelectFile = _IEFormElementGetObjByName($oForm, "open_file_element_ID") _IEAction($oFormSelectFile, "click") Second script #include <Clipboard.au3> While 1 $handle = WinWait("Choose File to Upload") Sleep(300) $file = _ClipBoard_GetData() ControlSend($handle, '', 'Edit1', $file & '{ENTER}') Sleep(300) WEnd Thanks alot Link to comment Share on other sites More sharing options...
TonyAntony Posted June 11, 2018 Share Posted June 11, 2018 On 13/12/2016 at 6:57 AM, Toan10921 said: Thanks alot Hello, I still dont get how did you make it work? Do you think you can post a full example? Thanks! Link to comment Share on other sites More sharing options...
Juvigy Posted June 12, 2018 Share Posted June 12, 2018 The example is full. The idea is that the first script starts another script to handle the 'choose file to upload' popup that stops the execution of the first script. After the second script handles the popup, the execution of the first script continues and the second one is closed. 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