File Downloads

File Downloads

This first dialog is displayed if you click a button, or link that causes a file to get downloaded. I guess this may first dialog may or may not appear, depending on what security settings you have chosen.

This dialog appears when you try to download a file. Its basically asking the location where you want to save it.

Solution 1

Try this as a solution:

prompt_message = "Do you want to open or save this file?"
window_title = "File Download"
save_dialog = WIN32OLE.new("AutoItX3.Control")
sleep 1
save_dialog_obtained = save_dialog.WinWaitActive(window_title,prompt_message, 25)
save_dialog.ControlFocus(window_title, prompt_message, "&Save")
sleep 1
save_dialog.Send("S")
save_dialog.ControlClick(window_title, prompt_message, "&Save")
save_dialog.WinSetTitle(window_title, prompt_message, "This is ForTesting" )
saveas_dialog_obtained = save_dialog.WinWait("Save As", "Save&in", 5)
sleep 1
path = File.dirname(__FILE__).gsub("/" , "\\" )+ "\\" + fileName
save_dialog.ControlSend("Save As", "", "Edit1",path)
sleep 4
save_dialog.ControlClick("Save As", "Save &in", "&Save")
save_fileAlreadyExists = save_dialog.WinWait("Save As", " ", 5)

Solution 2

I use this method to save a file, when ever the dialog is called.
Remember to use click_no_wait and not click when clicking the button that initiates the download dialog

def save_file(filepath)
    ai = WIN32OLE.new("AutoItX3.Control")
    ai.WinWait("File Download", "", 5)
    ai.ControlFocus("File Download", "", "&Save")
    sleep 1
    ai.ControlClick("File Download", "", "&Save", "left")
    ai.WinWait("Save As", "", 5)
    sleep 1
    ai.ControlSend("Save As", "", "Edit1",filepath)
    ai.ControlClick("Save As", "", "&Save", "left")
    ai.WinWait("Download complete", "", 5)
    ai.ControlClick("Download complete", "", "Close")
  end

Usage:

ie.link(:id, "myLink").click_no_wait
save_file("C:\\file.txt")

FILE Download Using FireWatir

 When you use do a file save in Firefox you dont get a save as dialog. So idea is to click on the download file button and then just press enter using autoit, as what I tried, it doesn't recognisez the window..

 Here is an example script for the same:

 #####################################################
require 'firewatir'
require 'watir'
require 'win32ole'
require 'rubygems'
ai = WIN32OLE.new("AutoItX3.Control")
ie=FireWatir::Firefox.new
#Go to AutoIt website
ie.goto("http://www.autoitscript.com/autoit3/downloads.shtml")
#Click Download AutoIt image
ie.image(:alt,'Download AutoIt').click
#Wait for the pop-up window with the specified title supplied to come
res=ai.WinWait("Opening autoit-v3-setup.exe","",30)
#Always try to Activate the pop-up window before using ControlClick fn()
res=ai.WinActivate("Opening autoit-v3-setup.exe")
ai.Send ("{ENTER}")


 #####################################################


 

 Hope this helps.

 Solution by: Pallavi. 

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.