Download File automatically? Make Selenium use Firefox defualt profile?

54 views
Skip to first unread message

Georg Horn

unread,
Dec 21, 2016, 12:21:50 PM12/21/16
to Selenium Remote Driver
Hi,

i am looking for a way to download a pdf file that is generated in the application i am testing. After clicking on the link, firefox opens a dialog that asks how to handle that file ("Open with" or "Save file") and after selecting "Save file" it opens the file selector dialog and you have to choose the dir where to save the file.

I tried the following:

my $profile = Selenium::Firefox::Profile->new;
$profile
->set_preference('browser.helperApps.neverAsk.saveToDisk' => 'application/pdf');
$driver
= Selenium::Remote::Driver->new('firefox_profile' => $profile);

but that does not work. It opens the dialog anyway.

You have to got to about:preferences#applications and set the action to "save file" for PDF files, then it saves the file without asking, but i can not do this setting with $profile->set_preference() because it is saved in the file mimeTypes.rdf in the profile directory and not in prefs.js

A possible solution would be to use my personal firefox profile where i have made this setting, but how can i do that? I tried:

my $profile = Selenium::Firefox::Profile->new('profile_dir' => '/home/username/.mozilla/firefox/blabla.default/');
$driver
= Selenium::Remote::Driver->new('firefox_profile' => $profile);

but it crashes with the error "Could not create new session: Java heap space at ..."

Kind Regards,
Georg

Daniel Gempesaw

unread,
Dec 30, 2016, 1:24:29 PM12/30/16
to Georg Horn, Selenium Remote Driver

Hmm, looks like there are a couple of different options to set in the profile? According to this stackoverflow answer, at least. But, I haven’t tried the suggestions in there. Perhaps they’ll help?

Good luck!


--
You received this message because you are subscribed to the Google Groups "Selenium Remote Driver" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-remote-d...@googlegroups.com.
To post to this group, send email to selenium-re...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-remote-driver/ba7513f9-9c9b-4508-b563-481892202f23%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

George Baugh

unread,
Nov 28, 2017, 1:25:23 PM11/28/17
to Selenium Remote Driver
If the dialog is generated by a 'file' type input, I believe you can send keys to the element after clicking it and then send enter to get it to work.

I recall having to do this a couple of years back, so my memory may be a bit fuzzy.  I'll see if I can't dig up where we did it and get an example for you.

Georg Horn

unread,
Dec 8, 2017, 2:10:19 PM12/8/17
to Selenium Remote Driver
This is for uploading files. If you download for example a pdf file, the browser opens a dialog and asks where to save it.

But i solved ths as follows:
- create a profile with "firefox -p"
- set preferences in this profile so that the browser does not ask where to save files (and eventually specify /tmp or so as folder where to save)
- make selenium use this profile with "java -Dwebdriver.firefox.profile=lisi -jar selenium-server-standalone-x-x-x.jar"
Reply all
Reply to author
Forward
0 new messages