How to download file in IE or FF

4,276 views
Skip to first unread message

DZ

unread,
Dec 21, 2011, 3:52:41 PM12/21/11
to robotframework-users
Hello everyone,

I recently started using RobotFramework with Selenium WebDriver. One
of our tests requires to download file from the browser (IE or FF). It
seems that RobotFramework libraries don't provide keyword to perform
this operation and all info i could find refers to using AutoIt. Is it
the only way to be able to download the file or there is a better way?

Thank you,
DZ

AndreasEK

unread,
Dec 21, 2011, 4:38:46 PM12/21/11
to robotframework-users
Hi,

I've described here, how to do it:

http://blog.codecentric.de/en/2010/07/file-downloads-with-selenium-mission-impossible/

Regards,
Andreas

David

unread,
Dec 21, 2011, 11:13:19 PM12/21/11
to robotframework-users
I created issue for project to track the enhancement request:

https://github.com/rtomac/robotframework-selenium2library/issues/24

DZ

unread,
Jan 4, 2012, 2:40:47 PM1/4/12
to robotframework-users
Thank you for such a prompt help.

This solution works just fine when file is written to server's disk
and therefore there is a URL. However there is another case where
bytes are being streamed from server's memory back to the browser and
there is no file URL. Given that it seems that the only solution would
be to use AutoIt tool to click darn Save button but I still have a
hope that there is a more elegant way. Am I hopeless? :)

Thank you

David

unread,
Jan 4, 2012, 7:00:51 PM1/4/12
to robotframework-users
Can you elaborate on that particular scenario of bytes streamed from
memory?

Even if served from memory, there is always a URL to make the request
against where the bytes are served via response. It's just that the
URL instead of being:

http://www.site.com/downloads/file.extension

becomes something like

http://www.site.com/dynamicContentGenerator/content/3490385903485

and the content is usually returned as some mime type (application/PDF
- I might have the type wrong here, or if no specific file format then
as appication/octect-stream - which will typically force a browser to
download/save file, whereas PDF, etc. will open with associated file
viewer).

So the file download method from URL should still work. You just need
to know the URL. What file extension you save it as can be based on
looking up the MIME type in response headers.

If browser doesn't show you the URL when testing manually, you'll need
a traffic sniffer (Wireshark or browser extensions like HttpFox,
liveHttpHeaders, ieHttpHeaders, etc.)

DZ

unread,
Jan 6, 2012, 4:06:24 PM1/6/12
to robotframework-users
Thank you, David

Here is more details:

I want to download a file but it requires form submission. For example
i have a form with password field. Submitting the form to the server
results in a file back from the server. I want to download that file.

David

unread,
Jan 7, 2012, 1:29:47 AM1/7/12
to robotframework-users
DZ,

In that case, the URL of the file download is then the URL that your
form submits to (i.e. the form's action attribute value in the HTML
source code, or in javascript if javascript is instead used to submit
the form). Other than looking through the source code, an HTTP traffic
sniffer can also help you sniff out the form submission URL as well.

However, this URL is not accessed as a normal HTTP GET request (that
you can type in browser to download). Instead it is an HTTP POST
request, which has same URL structure as a GET but you also send data
(i.e. the form submission of password and other data) along with the
URL request. You can't make a POST from browser without browser
extensions like the following for Firefox: RESTClient, HttpRequester,
Poster.

The HTTP response that the server sends back from the POST request
will then content the file to download. And if it's binary, you can't
really test it with the browser extensions mentioned above, so will
need to do so in code.

You can use code in Python to make the POST request, then save the
response you get back to file on disk.

There are two items that may make the download harder though:

* browser session and cookie - if the download that requires form
submission also requires a browser/server session, then you'll also
need to enable cookie support in Python code to allow the download to
work, else server will not allow download

* HTTPS secure access - if the form submission requires HTTPS, your
code needs to be able to handle that. I think Python HttpLib and
urllib should be ok, but not sure.
Reply all
Reply to author
Forward
0 new messages