Dashboard > Watir > ... > Pop Ups > File Downloads
Watir Log In View a printable version of the current page.
File Downloads
Added by Zeljko, last edited by Zeljko on May 23, 2008  (view change) show comment
Labels: 
(None)

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")
Go to contents, previous, next page.

Site running on a free Atlassian Confluence Community License granted to OpenQA. Evaluate Confluence today.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.6 Build:#812 Aug 06, 2007) - Bug/feature request - Contact Administrators