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?
Controling a FileSelectFile with COM commands
- Masonjar13
- Posts: 1555
- Joined: 20 Jul 2014, 10:16
- Location: Не Россия
- Contact:
Re: Controling a FileSelectFile with COM commands
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.
To interact with windows, you can use sends/clicks, control sends/clicks/text sets, or window messages. All can be found in the documentation.
Re: Controling a FileSelectFile with COM commands
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.
while first script is stop so second script "uploadInv.ahk" do the file search and upload work
this how I manage to do upload file via com
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
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
"When there is no gravity, there is absolute vacuum and light travel with no time" -Game changer theory