VBScript Autoit programming file upload

戏子无情 提交于 2020-01-17 08:17:08

问题


Hi guys, our company's website has this file upload button for uploading multiple images. How can I create a script that automatically selects the images then uploads them? I already know the path of each images on the client's PC. I just don't want to script a click on the file upload button since I get a headache trying to make that work. My current goal is to script it in Autoit with something like:

$files1 = "C:\TeamBuilding\Team Games.jpg"
$files2 = "C:\TeamBuilding\Team Prayer.jpg"
$oIE.getelementbyid("file").upload $files1, $files2

Then after the image upload the form is submitted. Obviously the code above is a fantasy :D I just need the part to script uploading the images instead of clicking the upload button. My Autoit script will modify the innerHTML of this form to add the script for auto-upload. Is this doable?

Summary: Instead of clicking the "Upload File" button I want a script to upload certain .jpg files. Right now what I'm doing is manually clicking the "Upload File" button then selecting all the JPEG files. Somebody suggested a script that will click the upload button then types the path of each images but I already tried those, was a headache, I'm asking for a script in VB (since Autoit seem to be VBScript language). Once I get that script, what I will do is just modify the innerHTML of my company's site so instead of a plain <input type="file" name="file" multiple=""> it will automatically upload the pictures without having the user manually placed the pictures


回答1:


This is where you start.

        #RequireAdmin ;Will give your script a permission elevation (sometimes its needed)

        #include <IE.au3>
        Opt("WinTitleMatchMode", 2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
        Opt("WinSearchChildren", 1) ;0=no, 1=search children also

        $oIE = _IEAttach("MyUploadPageTitle","windowtitle"); do _IEAttach()
        oInputFile = _IEGetObjByName($oIE, "file");get an object of a file input field

        _IEAction($oInputFile, "focus")

        $hIE = _IEPropertyGet($oIE, "hwnd")
        ControlSend($hIE, "", "Internet Explorer_Server1", " ")

        WinWait("Choose File", "", 30)
        Sleep(1000)
        WinActivate("Choose File")
        ControlSetText("Choose File", "", "[CLASS:Edit; INSTANCE:1]", $FileToUpload )
        Sleep(1000)
        WinActivate("Choose File")
        ControlSend("Choose File", "", "", "{ENTER}")

        WinWaitClose("Choose File", "", 5)
...


来源:https://stackoverflow.com/questions/29281875/vbscript-autoit-programming-file-upload

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!