2

I just started learning selenium with python


from selenium import webdriver

MY_PROFILE = "D:\\FIREFOX_PROFILE"

FFP = webdriver.FirefoxProfile(MY_PROFILE)

print(FFP.profile_dir)
# OUTPUT: C:\Users\ABC\AppData\Local\Temp\****\***
# But it should be OUTPUT: D:\FIREFOX_PROFILE

DRIVER = webdriver.Firefox(firefox_profile = FFP)

print(FFP.profile_dir)
# OUTPUT: C:\Users\ABC\AppData\Local\Temp\****\***
# But it should be OUTPUT: D:\FIREFOX_PROFILE

I want to save my profile somewhere so that I can use it later on.

I also tried creating RUN -> firefox.exe -p and creating a new profile (I can't use the created profile). Nothing works.

I am using:

  • Selenium Version: 2.53.6
  • Python Version: 3.4.4
  • Firefox Version: Various(49.0.2, 45, 38 etc)

I searched in Google but I can't solve it. Is there any way to save the profile?

Juan Carlos Ramirez
  • 2,054
  • 1
  • 7
  • 22
  • I recall spending days on this same issue too previously and wasn't successful at using a custom profile saved outside of the runtime. I think creating a custom profile during runtime may be the only solution – kerwei Oct 16 '18 at 02:54
  • How can I do that –  Oct 16 '18 at 02:55
  • There's an example here using java but the idea is similar [link](https://www.seleniumeasy.com/selenium-tutorials/firefox-profile-preferences-using-selenium-webdriver). Open up the your firefox config and then set your preferences as you would in setting the key-value pair in a dict. – kerwei Oct 16 '18 at 02:56
  • Check the `set_preference` method here [link](https://selenium-python.readthedocs.io/api.html#module-selenium.webdriver.firefox.firefox_profile) – kerwei Oct 16 '18 at 03:00

1 Answers1

0

You need to take help of os module in python

import os

there you get functions (like .getcwd() ) to described in Files and Directories. then use,

p = webdriver.FirefoxProfile()
p.set_preference('browser.download.folderList', 2 )
p.set_preference('browser.download.manager.showWhenStarting', false)
p.set_preference('browser.download.dir', os.getcwd())
p.set_preference('browser.helperApps.neverAsk.saveToDisk', 'text/csv/xls')
driver = webdriver.Firefox(p)

in short you can do so,

profile.set_preference("browser.helperApps.neverAsk.openFile","text/csv,application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml")

possible duplicate of Setting selenium to use custom profile, but it keeps opening with default

Ashish Kamble
  • 2,555
  • 3
  • 21
  • 29