Setting a custom browser.download.dir for Firefox using Webdriver

6,095 views
Skip to first unread message

Jonathan

unread,
Jan 5, 2012, 3:46:29 PM1/5/12
to Selenium Users
I'm testing an application that allows me to download a text file.
Since I don't want to code around the browser's download dialog box, I
thought I'd set a profile for it to just download the file without
confirmation.

Why doesn't the following work?

fp = webdriver.FirefoxProfile()
fp.set_preference("browser.download.dir", "/tmp" )
fp.set_preference("browser.helperApps.neverAsk.saveToDisk",
"text/plain")

driver = webdriver.Firefox(firefox_profile=fp)

When I execute this, the preferences appear to be set, looking in
fp.path/prefs.js, but when I look at Firefox->Edit->Preferences, the
downloads directory is the one from the default profile (Downloads).

I'm on Ubuntu 11.04, using Firefox 4.0.1, webdriver 2.5.0.

Krishnan Mahadevan

unread,
Jan 6, 2012, 6:39:32 PM1/6/12
to seleniu...@googlegroups.com
The latest version of selenium is 2.16.1
Can you please try in that?
> --
> You received this message because you are subscribed to the Google Groups "Selenium Users" group.
> To post to this group, send email to seleniu...@googlegroups.com.
> To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en.
>
>

--
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/

Mark Collin

unread,
Jan 9, 2012, 6:19:58 AM1/9/12
to seleniu...@googlegroups.com
Can you supply all of your code, the snippet pasted looks correct.

Another option would be to get the download link using selenium and then use
Java to download the file:

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

driver = webdriver.Firefox(firefox_profile=fp)

--


You received this message because you are subscribed to the Google Groups
"Selenium Users" group.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to
selenium-user...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/selenium-users?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

Christopher Tichenor

unread,
May 4, 2012, 12:54:53 PM5/4/12
to seleniu...@googlegroups.com
You've mostly got it right, but you also have to tell Firefox to actually use the directory you specified. So the code should go like this:
         
fp = webdriver.FirefoxProfile() 
fp.set_preference("browser.download.folderList", 2) # 0 means to download to the desktop, 1 means to download to the default "Downloads" directory, 2 means to use the directory you specify in "browser.download.dir"
fp.set_preference("browser.download.dir", "/tmp" ) 
          fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/plain") 

          driver = webdriver.Firefox(firefox_profile=fp)

Yevgeniy Semashko

unread,
Nov 21, 2014, 7:00:16 AM11/21/14
to seleniu...@googlegroups.com
fp = webdriver.FirefoxProfile()

fp.set_preference("browser.download.folderList",2)
fp.set_preference("browser.download.manager.showWhenStarting",False)

fp.set_preference("browser.download.dir", "/tmp")
fp.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/html")

but I have this error
[Error 3] The system cannot find the path specified: 'c:\\users\\semashko\\appdata\\local\\temp\\tmpx7susu/*.*'

CH!NN@ K

unread,
Nov 24, 2014, 6:29:24 AM11/24/14
to seleniu...@googlegroups.com
Hi Semashko , It is working for my functionality of direct download to my PC using Selenium Automation. please check it once then you will get any idea for your requirement. click on below link
http://techlearn.in/content/how-download-pdf-file-website   


---
Thanks & Regards,
Purushotham Karimbedu,
Druapl Developer and QA Engineer,
Website for Selenium : http://techlearn.in


--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.

To post to this group, send email to seleniu...@googlegroups.com.

Mark Collin

unread,
Nov 25, 2014, 3:06:42 AM11/25/14
to seleniu...@googlegroups.com
Looks like you are setting a *nix download path on a windows machine.  Try modifying the download directory to a windows style one.

I would also ask what you are trying to achieve with this code?  Are you actually checking any of the files you have downloaded?

Have a read of this:


and a watch of this:


Do you still need to do the test you are trying to do in the way you are trying to do it?
Reply all
Reply to author
Forward
0 new messages