m8L
m8L

Reputation: 119

AUTOIT Automating File Download in IE9 and above

I am presently working on a script to download a file using AUTOIT. The script works in the sense that it will open IE, attach to the window, enter the URL string to download the file and then send the keystrokes to download the file when the IE9 download manager prompt appears.

The problem i am having is that sometimes when the connection is slow, the IE9 download prompt takes too long to appear and the keystrokes miss their targets. Using SLEEP is out of the question, because it takes a variable amount of time to display the File Download and it will unnecessarily slow the script down if for example i have the script SLEEP for 6 seconds when the prompt displays in 1 second.

PS. I cannot use the INET get function because the URL i'm passing is to a Report Server, the report is generated there and the file is rendered down to me in the browser.

I was looking at the controlGetHandle function and would really appreciate it if anyone can give any ideas on how to navigate the IE download manager prompts. That is activate the script when the download prompt appears.

Thanks in advance guys.

Upvotes: 0

Views: 2986

Answers (2)

Milos
Milos

Reputation: 2946

Here it is

#include <IE.au3>
Opt("WinTitleMatchMode", 2)


Local $oIE = _IE_Example("form")

$oInputFile = _IEGetObjByName($oIE, "fileExample")
$FileToUpload = "c:\myfile.txt"

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

WinWait("Choose File", "", 30)

Sleep(1000)

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

Upvotes: 0

Andreas
Andreas

Reputation: 5609

I guess WinWait is the function that could help you here. It pauses the script until the denoted window exists and as a safe guard there is also a timeout parameter so that you could use:

WinWait("download", "" , 10000 )

This would wait for a window with "download" in its title until 10 seconds have passed.

Upvotes: 0

Related Questions