How to handle file download popups in Firefox?

122 views
Skip to first unread message

Margam

unread,
Dec 15, 2008, 5:40:26 PM12/15/08
to Watir General
Hello Everyone,
I have been trying to handle File Download pops in FF browser. I had
posted a similar question in the FireWatir group (http://
groups.google.com/group/firewatir/browse_thread/thread/
645846692f7d64fd?ie=utf-8&oe=utf-8&q=watir+-+file+download+in
+Firefox#903516a40a227883), But I thought it would be better here, as
I am actually using Watir.
My script works successfully until the popup is shown, but does
nothing after that. The code is very similar to the one that I use for
IE.
------------------
require 'watir'
require 'win32ole'

Watir::Browser.default='firefox'
$browser=Watir::Browser.new

def save_file(filename)
filepath = "c:\\#{File.basename(filename, '.rb')}"
sleep(10)
ai = WIN32OLE.new("AutoItX3.Control")
window_title = ai.WinGetTitle("[active]") # This is to get the
title of the popup. Since this changes in FF, for every file download.
sleep 1
ai.ControlFocus(window_title, "", "&OK")
sleep 1
ai.ControlClick(window_title, "", "&OK")
sleep 1
ai.ControlSend("Enter name of file to save to...", "",
"Edit",filepath)
sleep 1
ai.ControlClick("Enter name of file to save to...", "", "&Save")

window_title1 = "Enter name of file to save to..."
ai.ControlFocus(window_title1, "", "&Yes")
sleep 1
ai.ControlClick(window_title1, "", "&Yes")
end

$browser.goto("http://abcd.com")
sleep 2
$browser.link(:text, "zzz.zip").click
sleep 5
save_file("zzz")
--------------------------
The popup remains and nothing happens. The scripts finishes running
without any errors.
But the same code works great with IE. Can someone help in pointing
the problem here?


Also how to control Radio buttons using AutoIt (for the same file
download popup).
Thank you very much.

Margam

Margam

unread,
Dec 16, 2008, 1:24:50 PM12/16/08
to Watir General
Hello Everyone,
Can someone help me with this issue please. I need this working very
desperately for my project. Thank you very much.

Margam

al3kc

unread,
Dec 17, 2008, 5:41:27 AM12/17/08
to Watir General
Hi,

I use next code and it works for me

@ai = WIN32OLE.new("AutoItX3.Control")
@ai.WinWaitActive("[REGEXPTITLE:Opening]")
@ai.Send("{ENTER}")
@ai.WinWait("Enter name of file to save to…", "", 5)
@ai.WinActivate("Enter name of file to save to…")
sleep(7)
@ai.Send("#{$test_directory}\\#{name}")
sleep(5)
@ai.ControlClick("Enter name of file to save to…", "", "&Save")
sleep(1)

To print path for saving I use @ai.Send("#{$test_directory}\\#
{name}") instead of ai.ControlSend("Enter name of file to save
to...", "",
"Edit",filepath) because this always type massed text.

Margam

unread,
Dec 17, 2008, 1:09:34 PM12/17/08
to Watir General
Hi al3kc,

THANK YOU very much. Your code snippet worked great the very first
time. I just had to modify it a little for my use, but worked just
fine.

I was having another question regarding the file download popup and
was wondering if you could help with some advice.
How to handle the radio buttons ("Open with" and "Save File") in the
popup. The default being "Save File" works for me now. But how do I
choose the other option?
Also how to check a check box in the popup.

Thank you very much once again.

Margam

Wilson Xu

unread,
Dec 17, 2008, 9:04:07 PM12/17/08
to Watir General
The first step: Use Send("{TAB}") event to focus on the radio what you
want.
The second step: Use Send("{DOWN}") or Send("{UP}") event to select
radio,
I think this way is not stable, but can resolve your issue.

Wilson Xu

al3kc

unread,
Dec 18, 2008, 3:35:28 AM12/18/08
to Watir General
I cannot set radio button. It's an issue for me too. I just have
selected "Save file" by default in FF.

al3kc

unread,
Dec 18, 2008, 6:56:03 AM12/18/08
to Watir General
on http://www.autoitscript.com/forum/index.php?showtopic=81915&hl=firefox+download+window
I have found next code:

ControlClick("Opening", "", "MozillaWindowClass1", "left", 1, 46, 158)
sleep(1000)
ControlClick("Opening", "", "MozillaWindowClass1", "left", 1, 241,
237)
sleep(1000)

All elements in "MozillaWindowClass1" has constant coordinates so you
can click any element in this window by coordinates.

Margam

unread,
Dec 18, 2008, 12:35:22 PM12/18/08
to Watir General
Hey guys,
Thanks for the input. I will certainly try, as soon as I finish with
my current project. Thanks.

Margam

On Dec 18, 3:56 am, al3kc <aleks.kiev...@gmail.com> wrote:
> onhttp://www.autoitscript.com/forum/index.php?showtopic=81915&hl=firefo...

Wilson Xu

unread,
Dec 18, 2008, 11:14:33 PM12/18/08
to Watir General
Another way, I think you can use MouseClick() API in AutoITx to select
the radio box.

Wilson Xu
Reply all
Reply to author
Forward
0 new messages