Attckdog Posted August 1, 2011 Posted August 1, 2011 I feel like an idiot for how long I've been trying to get this to work... Let's Start off by saying that I am not quite a newb to this. I generally catch on fast to code related subjects. That being said this is my first real attempt at IE automation. I have used autoIT for plenty of other things. Mostly excel, file system and program automation. ----------------------- What I'd like to do: Upload images from a list of filenames to Vendio.com's Image hosting. Problem I am encountering: I cannot find the proper command/code to first Collect the input's location and second Input File names. I believe I have used every kind function in the help file to no avail. Section of HTML I need to interact with: <FORM name="zupload_form_1" id="zupload_form_1" METHOD="POST" ACTION="http://www.vendio.com/my/ihost/uploadimage.html?" ENCTYPE="multipart/form-data" TARGET="zoom_upload"> <INPUT type="file" name="img_file" size="30" id="img_file" onChange="on_file_change(1);"> </FORM> I am not asking for the entire script, just give me a shove in the right direction if you would be so kindest. If you would need to any other information I'll be monitoring this thread for a good hour. Thanks, Attck A true renaissance man
somdcomputerguy Posted August 1, 2011 Posted August 1, 2011 See _IEFormElementSetValue, and it's example code, in the Helpfile. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change.
DaleHohm Posted August 1, 2011 Posted August 1, 2011 (edited) See my sig for a way to work with type=file inputs. The way they work is restricted in IE (not in AutoIt) for secutity reasons. Dale Edited August 1, 2011 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
Attckdog Posted August 2, 2011 Author Posted August 2, 2011 Thank you for your reply's I will look into both. -Attck A true renaissance man
Attckdog Posted August 2, 2011 Author Posted August 2, 2011 Awesome I have the script working with DaleHohm's suggestion. I have everything down except actually submitting the Upload. It seems like another issue of not being sure what to use to click or submit the upload. I'd rather stay away from using mouseMove and mouseClick. It's not being recognized by: _IEGetObjById($oIE, "Upload") or _IEFormSubmit() Here's the HTML: <input class="button" onclick="javascript:return do_upload();" type="button" value="Upload"> For the time being I'm going to try to reuse the code from DaleHohm's code. Thanks For your help! A true renaissance man
PeterPE Posted August 3, 2011 Posted August 3, 2011 I think this is because of the security feature Dale mentioned
Attckdog Posted August 3, 2011 Author Posted August 3, 2011 I think this is because of the security feature Dale mentioned Yeah, that was for the browse button. Or do you mean to say that the upload button is also being protected somehow and cannot be interacted with by normal _IE methods? Even with Dales code that he suggested I cannot seem to get anything to find the object. That's where I am stuck. This Code works for the browse / file input form. Now the upload button cannot be found by the _IEGetObjById function. $oT = _IEGetObjById($oIE, 'zupload_form_1') MouseMove(_IEPropertyGet($oT, "screenx") + _IEPropertyGet($oT, "width") - 10, _ _IEPropertyGet($oT, "screeny") + _IEPropertyGet($oT, "height") / 2) MouseClick("left") _WinWaitActivate("Choose File to Upload","Look &in",3) $hChoose = WinGetHandle("Choose File to Upload") ControlSetText($hChoose, "", "Edit1", $sCellValue & "D.jpg") ControlClick($hChoose, "", "Button2") After Looking at the HTML Here: <input class="button" onclick="javascript: return do_upload();" type="button" value="Upload"> I can easily tell its javescript, so is there somehow a way to directly tell the webpage to call the "return do_upload()" function? /me google.com Java+autoit -Attck A true renaissance man
Attckdog Posted August 3, 2011 Author Posted August 3, 2011 (edited) Can't find the edit button for this forum, Rage... Anyways, Slight Update / double post. ( sorry, would have been an edit but sigh..) broke down and used MouseMove and MouseClick to get the Upload button to work. I am now working on making an already Uploaded Test for the script to make sure I don't come up with any "Image with this name already exists Errors" I'm going to make a new thread about that as it is a completely different problem and topic. --------------EDIT------------------------ Success, Not perfect but here is the script that I was working on. Currently the only thing I can see being an issue with it is the mouse cords changing for the upload button. expandcollapse popup; *******************************************************; ; Vendio Upload From File ;Got Help/Code From: DaleHohm(AutoIT Forums) And Tvern(AutoIT Forums) ; *******************************************************; ; ; #include <IE.au3> #include <Excel.au3> HotKeySet("{PAUSE}", "TogglePause") HotKeySet("{ESC}", "Terminate") Global $Paused Global $sCellValue ;_ExcelBookOpen(@DesktopDir & "\test.xls") $oExcel = _ExcelBookAttach(@DesktopDir & "\test.xls") ;Excel Workbook with A1-10,000 with SKU's $i = 1 ; excel Row $sCellValue = _ExcelReadCell($oExcel, $i, 1);populate for intial use $oIE = _IECreate("http://www.vendio.com/my/ihost/stdupload.html");start IE with upload page (Assume Logged in and Full Screen) While 1 BODY();start Script WEnd Func BODY() While $i < 10000 $sCellValue = _ExcelReadCell($oExcel, $i, 1) If $sCellValue = "" Then ;test cell for empty ConsoleWrite("Cell A" & $i & " is Empty Assume Finished, Terminate Script" & @CR) Terminate() EndIf ConsoleWrite($sCellValue & " ------------Start Tests----------" & @CR) ;Test if Image file exist If FileExists("I:\finished ima on posterserver jpegs\" & $sCellValue & "D.jpg") Then _ExcelWriteCell($oExcel, "File Test Sucess " & $sCellValue & "D.jpg", $i, 2) ConsoleWrite($sCellValue & " File Test Sucess " & $sCellValue & "D.jpg" & @CR) Else _ExcelWriteCell($oExcel, "File Test Failed " & $sCellValue & "D.jpg", $i, 2) ConsoleWrite($sCellValue & " File Test Failed " & $sCellValue & "D.jpg" & @CR) MsgBox(0, "If FileExist Has failed .jpg", "File Test Has failed Skipping " & $sCellValue & ".jpg on Line " & $i, 1) $i = $i + 1 ;skip if file not found BODY() EndIf ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;test if already uploaded _UploadTester() ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; $oT = _IEGetObjById($oIE, 'zupload_form_1') ;find browse to file button MouseMove(_IEPropertyGet($oT, "screenx") + _IEPropertyGet($oT, "width") - 10, _ _IEPropertyGet($oT, "screeny") + _IEPropertyGet($oT, "height") / 2) MouseClick("left");click browse _WinWaitActivate("Choose File to Upload", "Look &in", 3) ; Wait for Browse window $hChoose = WinGetHandle("Choose File to Upload") ; get Browse Window title and save to $hChoose ControlSetText($hChoose, "", "Edit1", $sCellValue & "D.jpg") ; inout filename ControlClick($hChoose, "", "Button2") ; submit filename/ location Sleep(2000) ; give website time to work MouseMove(41, 174) ; move mous to Upload Button, top left Sleep(1000) ; sleep for good measure MouseClick("left") ; click Upload Button _IELoadWait($oIE);wait for website to load Sleep(10000);sleep for good measure $UploadMore = _IEGetObjById($oIE, 'upload_act');find Upload more button MouseMove(_IEPropertyGet($UploadMore, "screenx") + _IEPropertyGet($UploadMore, "width") - 10, _ _IEPropertyGet($UploadMore, "screeny") + _IEPropertyGet($UploadMore, "height") / 2) MouseClick("left") ; Move to and click the Upload More Button Sleep(1000);sleep for good measure $i = $i + 1 ; Move to next line WEnd EndFunc ;==>BODY ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;----------FUNCS------------------------------------------------ Func _UploadTester() ;Adjusted to Work with While Loops $oHttpRequest = ObjCreate("MSXML2.ServerXMLHTTP") $sTestUrl = "http://imagehost.vendio.com/" & $sCellValue & "D.jpg" $ResolveTimeout = 500 $ConnectTimeout = 500 $SendTimeout = 500 $ReceiveTimeout = 500 $oHttpRequest.SetTimeouts($ResolveTimeout, $ConnectTimeout, $SendTimeout, $ReceiveTimeout) $oHttpRequest.Open("GET", $sTestUrl) $oHttpRequest.Send If $oHttpRequest.Status = 200 Then;If URL exist then Image already uploaded ConsoleWrite($sTestUrl & " Already Uploaded " & $sCellValue & "D.jpg" & @CR) _ExcelWriteCell($oExcel, " Already Uploaded " & $sCellValue & "D.jpg", $i, 3) MsgBox(0, "Error Already Uploaded", "Upload Test Has failed Skipping " & $sCellValue & " on Line " & $i, 1) $i = $i + 1; Skip to next line BODY() EndIf If $oHttpRequest.Status = 404 Then;URL 404 means it isn't uploaded already Continue Script ConsoleWrite($sTestUrl & " Clear to Upload " & $sCellValue & "D.jpg" & @CR) _ExcelWriteCell($oExcel, " Clear to Upload " & $sCellValue & "D.jpg", $i, 3) EndIf $oHttpRequest = "" ; clears var for next use EndFunc ;==>_UploadTester Func _WinWaitActivate($title, $text, $timeout = 0) WinWait($title, $text, $timeout) If Not WinActive($title, $text) Then WinActivate($title, $text) WinWaitActive($title, $text, $timeout) EndFunc ;==>_WinWaitActivate Func TogglePause() $Paused = Not $Paused While $Paused Sleep(100) ToolTip('Script is "Paused"', 0, 0) WEnd ToolTip("") EndFunc ;==>TogglePause Func Terminate() MsgBox(0, "Script Stopped", "Script Has Stopped either Finished or Errored") Exit 0 EndFunc ;==>Terminate Edited August 4, 2011 by Attckdog A true renaissance man
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