3

I am having an automation script which worked well before the recent mozilla update. The selenium-python script automates some of my browser actions, and save certain reports (csv) to a defined location.

I have been using selenium 2.53.6, which uses the following code :

profile = webdriver.firefox.firefox_profile.FirefoxProfile()
profile.set_preference('browser.helperApps.neverAsk.saveToDisk',"text/csv, application/pdf,application/octet-stream")
profile.set_preference('browser.download.folderList',2)
profile.set_preference("browser.download.manager.showWhenStarting",False)
profile.set_preference('browser.download.dir','D:\Downloads')
driver = webdriver.Firefox(firefox_profile=profile)

Currently I use selenium-python 3.0.1 and Firefox 48. Here I had added the geckodriver path to environment variables and was able to launch firefox using the code below:

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

caps = DesiredCapabilities.FIREFOX
caps["marionette"] = True
driver = webdriver.Firefox(capabilities=caps)

I am curious on how to do a profile.set_preference equivalent in firefox-marionette driver. I couldn't find any documentations on it.

Please advise.

Surabhil Sergy
  • 1,946
  • 1
  • 23
  • 40
  • Duplicate of [Selenium using Python - Geckodriver executable needs to be in PATH](https://stackoverflow.com/questions/40208051/selenium-using-python-geckodriver-executable-needs-to-be-in-path) – cachius May 21 '22 at 21:27

1 Answers1

1

You can pass profile as well to launch FirefoxDriver as :-

driver = webdriver.Firefox(capabilities=caps, firefox_profile=profile)

You can also set firefox_profile into capabilities as :-

caps["firefox_profile"] = profile
driver = webdriver.Firefox(capabilities=caps)
Saurabh Gaur
  • 23,507
  • 10
  • 54
  • 73
  • Thanks for this, but it is not yet working. `profile.set_preference("browser.download.folderList",2) profile.set_preference("browser.download.manager.showWhenSta‌​rting", False) profile.set_preference("browser.download.dir", 'C:\Users\Surabhil\Desktop\Downloads') profile.set_preference("browser.helperApps.neverAsk.saveToDi‌​sk", "application/xls;text/csv")` Mine is an xls file. Also when I checked about:config of the browser, I could still see browser.download.folderList as 1 – Surabhil Sergy Oct 17 '16 at 15:23
  • 1
    Also if my understanding is correct , Selenium 3 will take default profile as marionette . Is this why it is not taking the firefox driver profile ? – Surabhil Sergy Oct 17 '16 at 16:16
  • @SaurabhGaur You are sure it works with Selenium 3.0.1 and Geckodriver 0.11.1 ? I have used FirefoxOptions to create a driver but settings are ignored. – Vojtěch Dohnal Nov 28 '16 at 14:36
  • I'm also having trouble with auto download--is there an update to this? Here is my code: `fp = webdriver.FirefoxProfile()` `fp.set_preference("browser.download.folderList", 2) fp.set_preference("browser.download.manager.showWhenStarting‌​",False) fp.set_preference("browser.download.dir", "H:\Downloads") fp.set_preference("browser.download.downloadDir","H:\Downloa‌​ds") fp.set_preference("browser.download.defaultFolder","H:\Downl‌​oads")` `firefox_capabilities['marionette'] = True` `driver = webdriver.Firefox(capabilities=firefox_capabilities,firefox_‌​binary=binary, firefox_profile = fp)` – d84_n1nj4 Dec 30 '16 at 15:52
  • I came across this thread: [link](https://github.com/mozilla/geckodriver/issues/236) which eventually ends with this thread: [link](https://github.com/SeleniumHQ/selenium/issues/2572). The latter thread seems to be the most recent discussion on this matter. I asked how to update my code, and will make an update to this thread when it is figured it out. – d84_n1nj4 Dec 30 '16 at 16:45
  • 1
    I believe I solved the issue here [Python Firefox Download Profile](http://stackoverflow.com/questions/41644381/python-set-firefox-preferences-for-selenium-download-location/41683377#41683377). – d84_n1nj4 Jan 16 '17 at 19:15