Controling a FileSelectFile with COM commands

Get help with using AutoHotkey and its commands and hotkeys
clina1j
Posts: 49
Joined: 22 Apr 2016, 18:39

Controling a FileSelectFile with COM commands

14 Oct 2016, 17:47

So, I am trying to automate a document upload process. First you have to enter a large amount of metadata, then you have to select the file to upload and then you are done. Inputting the metadata was far more complicated than it needed to be, but I have finally reached the second part. However, the website I have to work with brings up a standard file browser/selector. Like the one that AHK brings up if you use "FileSelectFile".

I have the file location all put together as a wonderfully neat string, all the way down to "C:". I feel like there should be some standard COM commands to send the file location as a string to that browser, and then make it select the file at the other end of it. But I cannot find them in the help pages. I keep getting lead to help pages for "FileSelectFile", and other GUI support.

Do anyone know where that help is? Or (if you don't know where it is to be found either) how to control a standard file browser window?
User avatar
Masonjar13
Posts: 1515
Joined: 20 Jul 2014, 10:16
GitHub: Masonjar13
Location: Не Россия

Re: Controling a FileSelectFile with COM commands

14 Oct 2016, 23:02

Why do you feel there would be a COM interface for a dialog box?

To interact with windows, you can use sends/clicks, control sends/clicks/text sets, or window messages. All can be found in the documentation.
OS: Windows 10 Pro | Editor: Notepad++
My Personal Function Library | Old Build - New Build
User avatar
Xeo786
Posts: 238
Joined: 09 Nov 2015, 02:43
Location: Karachi, Pakistan

Re: Controling a FileSelectFile with COM commands

15 Oct 2016, 05:01

I was stuck to same type of issue. COM wait for file to be selected then you can trigger upload. I have little knowledge about com so I have manage to upload file with two separate ahk and msg box.

Code: Select all

wb := IEGet("exp.o Booking")

; here Input required data to wb and then go to upload page

wb.document.getElementByid("selectedDocumentType").value := "COMMERCIAL_INVOICE"
wb.document.getElementByid("documentDescription").value := "Commercial Invoice For Booking"
run, "D:\My Documents\AHK scipts\uploadInv.ahk"                                      ; an ahk run to select file
wb.document.getElementByid("fileUpload").click()                                    ; this is where this script wait for file to be uploaded
MsgBox, 0,  Expo Booking Msg , do not press ok just wait                           ; i don't know how this msg appear but wb will not go further until you select file.
													      ; but this msg some how do appear stop this script to go further and wait 
													      
IEGet(name=""){
    IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame ; Get active window if no parameter
    Name := (Name="New Tab - Windows Internet Explorer")? "about:Tabs":RegExReplace(Name, " - (Windows|Microsoft) Internet Explorer")
    for WB in ComObjCreate("Shell.Application").Windows
        if wb.LocationName=Name and InStr(wb.FullName, "iexplore.exe")
        return WB
    } ; by jethrow
return
while first script is stop so second script "uploadInv.ahk" do the file search and upload work

Code: Select all

; search for upload file via loop files or specified file
; uploadfile := whatever 

wb := IEGet("exp.o Booking")
WinWait, Choose File    ; this will wait for select file triggered previously at "wb.document.getElementByid("fileUpload").click() "
WinActivate, Choose File
sleep, 200
ControlSetText, Edit1, %uploadfile%, Choose File
sleep, 200
send, {enter}
upload := wb.document.getElementByid("bookingDocuments").action
;wb.document.getElementByid("upload").onclick                                   ;this didn't worked for me :(
wb.document.getElementByid("upload").click(upload)                            ; this worked 
While wb.readyState != 4 || wb.document.readyState != "complete" || wb.busy ; wait for the page to load
    sleep, 100

WinActivate,  Expo Booking Msg ; this will activate msg created previously
send, {enter}
return

IEGet(name=""){
    IfEqual, Name,, WinGetTitle, Name, ahk_class IEFrame ; Get active window if no parameter
    Name := (Name="New Tab - Windows Internet Explorer")? "about:Tabs":RegExReplace(Name, " - (Windows|Microsoft) Internet Explorer")
    for WB in ComObjCreate("Shell.Application").Windows
        if wb.LocationName=Name and InStr(wb.FullName, "iexplore.exe")
        return WB
    } ; by jethrow

this how I manage to do upload file via com :HeHe:
"When there is no gravity, there is absolute vacuum" -Game changer theory

Return to “Ask For Help”

Who is online

Users browsing this forum: boiler, Google [Bot], scriptor2016, stiuna, tatagi, tmplinshi and 41 guests