[webdriver] Handling Firefox Download Window

4,253 views
Skip to first unread message

Nilesh

unread,
Jan 23, 2012, 3:22:13 PM1/23/12
to webdriver
I know this question has been asked before but here I go again, I am
using Firefox 3.6, Selenium 2.17 jar and windows XP.

In my app clicking on a menu called 'Export' prompts the user with the
firefox download dialog that has 'open the file', 'save' radio buttons
and OK,Cancel buttons. The file that is being exported is a CSV file
which can be opened with excel. In order to automatically save the
file in the given directory and eliminate the firefox download dialog
box, I tried to use firefox profile to set the download directory,
folder set and disabled the saveToDisk dialog(code below). Even after
trying the profile below, I still get the firefox download dialog box.
I tried different versions of selenium but still no luck.

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.dir", "c:\\Selenium");
profile.setPreference("browser.download.folderList", 2);

profile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/
pdf");
driver = new FirefoxDriver(profile);

I also tried setting other flags below that did not work either. I
also changed the mime type to "application/excel" but that had no
effect. Is there anything I am missing here?

profile.setPreference("browser.download.useDownloadDir", false);
profile.setPreference("browser.download.manager.showWhenStarting",
false);

Thanks!

David

unread,
Jan 23, 2012, 9:19:04 PM1/23/12
to webdriver
I'd like to hear responses from others on this as well. Haven't
encountered need to work with file downloads with Web Driver yet.

You might want to try also the MIME types for CSV: "text/comma-
separated-values" and "text/csv" as CSV does not equal Excel.

Also I assume when you mention MIME type, you refer to changing it for
such code you referenced:

profile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/
pdf");

If it helps any, you could also try predefining a custom FF profile
(directory) and load that with WebDriver code rather than create a new
custom profile. Predefine a profile directory works same as in
Selenium RC, only you pass the directory in code to the FirefoxProfile
constructor rather than pass it as parameter argument to selenium
server on startup.

Mark Collin

unread,
Jan 24, 2012, 4:43:56 AM1/24/12
to webd...@googlegroups.com
Here's my solution:

https://github.com/Ardesco/Ebselen/blob/master/ebselen-core/src/main/java/co
m/lazerycode/ebselen/customhandlers/FileDownloader.java

It uses selenium to get the download link and then downloads it
programmatically using the apache commons library.

--
You received this message because you are subscribed to the Google Groups
"webdriver" group.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to
webdriver+...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/webdriver?hl=en.


--
This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.

If you have received this email in error please notify postm...@ardescosolutions.com

Dreamer

unread,
Jan 24, 2012, 7:03:57 AM1/24/12
to webdriver
Hi Mark,

Had this Issue last week, looking into AutoIT. It works with Java and
C#. Although it feels like a hack.



On Jan 24, 9:43 am, "Mark Collin" <m...@ardescosolutions.com> wrote:
> Here's my solution:
>
> https://github.com/Ardesco/Ebselen/blob/master/ebselen-core/src/main/...
> For more options, visit this group athttp://groups.google.com/group/webdriver?hl=en.
>
> --
> This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.
>
> If you have received this email in error please notify postmas...@ardescosolutions.com

Mark Collin

unread,
Jan 24, 2012, 7:17:08 AM1/24/12
to webd...@googlegroups.com
AutoIt is windows only hence why I don't like using it.

I normally work in *nix environments, but the implementation below should be
cross browser/cross OS.

Hi Mark,

If you have received this email in error please notify postm...@ardescosolutions.com

Nilesh

unread,
Jan 24, 2012, 9:29:59 AM1/24/12
to webdriver
Hi David,
I tried 'text/csv' MIME type below and it worked like a charm. Thanks
so much!

profile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/
csv");

David

unread,
Jan 25, 2012, 1:22:24 AM1/25/12
to webdriver
> AutoIt is windows only hence why I don't like using it.
>
> I normally work in *nix environments, but the implementation below should be
> cross browser/cross OS.

A cross platform solution to AutoIt would be using tools like Sikuli
or AutoPy

https://github.com/msanders/autopy

Mark Collin

unread,
Jan 25, 2012, 6:38:32 AM1/25/12
to webd...@googlegroups.com
My solution is designed to be lightweight and easy to implement.

In my opinion pulling in another automation framework just to click on one
button is a bit OTT.

Don't get me wrong Sikuli looks good and I have used AutoIt before to great
effect, but If you are going to write scripts for a different automation
framework why bother with Selenium at all? You may as well do all of your
automation in in your selected framework rather than have a cobbled together
solution that selects bits and pieces of multiple automation frameworks.
The OCD in me shudders at the though of something glued together with a
mixture of <yourLanguageOfChoice>, shell scripts, batch files, and (in my
opinion) misuse of build servers.

-----Original Message-----
From: webd...@googlegroups.com [mailto:webd...@googlegroups.com] On
Behalf Of David
Sent: 25 January 2012 06:22
To: webdriver
Subject: [webdriver] Re: Handling Firefox Download Window

https://github.com/msanders/autopy

--

David

unread,
Jan 25, 2012, 4:58:20 PM1/25/12
to webdriver
Mark, agreed on the framework of choice statement. However, I want to
point out that depending on language of choice, you don't have to
cobble two frameworks together, that happens when you use an
unsupported language, or for beginners who don't know the advanced
APIs to some tools.

Sikuli supports API calls to it from Java and Python (through Jython)
so if one is using Selenium in either of those languages, you can
integrate natively all the code in Java. Only if you use other
languages (C#, Ruby, Perl, etc.) are you then forced to cobble
together via shell script calls to Sikuli from your Selenium language.

Similarly AutoIt also has an ActiveX/COM API plus C++ DLL API, so if
using a language that supports COM, or can call win32 (C/C++) based
DLLs, then you can also combine AutoIt calls with Selenium all in one
framework. Only novices or those using a less versatile language will
have to resort to compiling an AutoIt executable and then run
executable via a shell process call from Selenium language of choice.

Using the tools this way is no different than your example of
filedownloader class in Java. Because if one used a different Selenium
language, they too would have to reimplement your downloader class
using the libraries of that language. Except that for your case, that
functionality is much more available across languages than say Sikuli
and AutoIt.
> For more options, visit this group athttp://groups.google.com/group/webdriver?hl=en.
>
> --
> This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.
>
> If you have received this email in error please notify postmas...@ardescosolutions.com

Krishnan Mahadevan

unread,
Jan 25, 2012, 10:10:40 PM1/25/12
to webd...@googlegroups.com
Blame my curiosity here but aren't sikuli and autoit restricted to working only for local runs? Do they work even for grid runs? I was under the assumption that they dont support grid runs.
Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/

David

unread,
Jan 25, 2012, 10:39:13 PM1/25/12
to webdriver
Krishnan,

Yes, you are correct, but not completely. By current available
architecture/implementation, those tools combined with Selenium are
restricted to local runs, due to the fact that:

* Selenium Grid doesn't support them
* there is no Sikuli Grid, nor AutoIt Grid

However, should that type of support come in the future then they can
be run in Grid mode. The problem right now is a lack of demand for
said tools in Grid mode (though in other posts, I do know there is
demand, just not much), and lack of developers with time and wish to
implement such. I will look into it when I have time, not high on my
priority list either (too much work to research & implement).

But I do have a simpler theoretical approach that can make use of
those tools in a grid mode, utilizing a mapping of Selenium nodes with
external (non-Selenium) server nodes that also run Sikuli and AutoIt
(separately from Selenium). That is run 2+ node servers on same node
to be able to run Selenium + desired tool on a particular node. It
just needs to be proven out. It is described here:

http://autumnator.wordpress.com/2011/12/22/autoit-sikuli-and-other-tools-with-selenium-grid/

On Jan 25, 7:10 pm, Krishnan Mahadevan

Mark Collin

unread,
Jan 26, 2012, 4:41:29 AM1/26/12
to webd...@googlegroups.com
I think we have different definitions of cobbling together a solution :)

I'm not suggesting that you should use my solution for anything other than
Java. You could rewrite the solution in <YourLanguageOfChoice>, it should
be fairly simple to do something similar with most languages. The other
option from a Java point of view would be to write a robot class to interact
with the GUI, but again it's a very complex solution for the requirements.

I'm a big believer of KISS (Keep It Simple Stupid) and lets face it if you
have a hyperlink that is enabled and links to a file there is really no
difference in clicking on the link and letting the browser download it and
effectively doing a wget on the url. I do wonder why people want to do so
many download tests, do they actually look at the files they download (I'll
bet most people don't) or do they just want to know that something is there
to download? If you want to know the link exists on the server you don't
even need to download it, you can just request it and ensure that you get a
valid http response. Not downloading the whole thing would probably make
your tests faster waste less bandwidth, reduce your diskspace requirements
and maybe even save the odd kitten!

So after the above mini rant why did I write the downloader function?

I wrote the linked function so that I can download excel files and open them
up and programmatically check the data in them (some sites I have tested
have offered an excel download of the tabular data displayed on the screen,
so I would download the excel file and check that the data in the file
matches the data on the screen), I suspect many people wanting the download
functionality don't do anything like this.

IMHO the default position for download tests should be don't bother, it's
not actually giving you anything worthwhile. It may make somebody who is
technically inept gasp in wonder that you have managed to download 1GB of
files from the test webserver automatically, but what has it actually told
you as a tester and what extra confidence has it given your devs?

If you have received this email in error please notify postm...@ardescosolutions.com

David

unread,
Jan 26, 2012, 4:34:07 PM1/26/12
to webdriver
Mark, I agree with your point about testing file downloads.

For my case, though we haven't deployed actual testing solution for
test environment constraints, for enhanced test coverage, we have need
to test file download as part of test that involves downloading an
Adobe Illustrator file but open directly rather than save to file
first (or could do that but more steps) and from Illustrator, run some
processing scripts to output file content as PDF stored on fileshare
and then verify the output PDF from web app. As this is a complex
system scenario that isn't purely web-based, Selenium alone plus some
filedownloader class can not do the job. My prototype made use of
AutoIt and Sikuli to manage the Windows desktop GUI portion
(Illustrator and PDF). And to account for grid deployment, made use of
XML-RPC servers that drive AutoIt and Sikuli and call them from test
code so that test can run in local or a grid mode. Of course the full
grid mode design was never completed. May seem complicated indeed and
better off manual testing but repeating said test often is laborious
and to some extent makes sense to automate where possible.
> For more options, visit this group athttp://groups.google.com/group/webdriver?hl=en.

Mark Collin

unread,
Jan 27, 2012, 1:34:39 AM1/27/12
to webd...@googlegroups.com
Certainly sounds like a complex case and I can see why you went down that
route, however I would ask why you didn't use AutoIt/Sikuli for the whole
thing rather than bundle Selenium in as well?

--


This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.

If you have received this email in error please notify postm...@ardescosolutions.com

David

unread,
Jan 27, 2012, 8:15:52 PM1/27/12
to webdriver
Selenium was still used as our test framework utilized it and because
Selenium is more robust in automating the web UI portion than to do it
through AutoIt or Sikuli, and allowed code reuse for the web UI
portion.

A majority of our tests are purely Selenium with a few exceptions.
> If you have received this email in error please notify postmas...@ardescosolutions.com

goud

unread,
Oct 31, 2013, 8:07:09 AM10/31/13
to webd...@googlegroups.com
Hey Nilesh can you help me with this on how you resolved, i am using C# and Webdriver with Visual Studio

Rakesh Kirola

unread,
Dec 25, 2013, 6:20:24 AM12/25/13
to webd...@googlegroups.com

Nilesh

unread,
Jul 15, 2014, 8:22:04 PM7/15/14
to webd...@googlegroups.com
For those interested, I solved it like this,

          FirefoxProfile profile = new FirefoxProfile();
 profile.setPreference("browser.download.dir", "/Users/nikulkarni");
 profile.setPreference("browser.download.folderList", 2);
 profile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/csv");
 WebDriver driver = new FirefoxDriver(profile);
Reply all
Reply to author
Forward
0 new messages