23

First, I want to use some addons while selenium controlling my firefox.

So, i tried load default profile of firefox in selenium code.

My code:

from selenium.webdriver.firefox.firefox_profile import FirefoxProfile

profile_path = r'C:\Users\Administrator\AppData\Roaming\Mozilla\Firefox\Profiles\y1uqp5mi.default'
default_profile = FirefoxProfile(profile_path)

driver = webdriver.Firefox(service=service, options=options, firefox_profile=default_profile)

But, when i start the code, a DeprecationWarning happened: firefox_profile has been deprecated, please pass in an Options object

I search a lot and i don't think it's a difficult problem, but sadly i can't solve this problem finally, maybe my bad english encumber me... ...

0m3r
  • 12,286
  • 15
  • 35
  • 71
cmy2019
  • 239
  • 1
  • 2
  • 4

3 Answers3

27

Here is the documentation for this: https://www.selenium.dev/documentation/webdriver/capabilities/driver_specific_capabilities/#setting-a-custom-profile

I tried this locally and it worked:

EDITED: I've changed the code, so there are no deprecation warnings

from selenium.webdriver import Firefox
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options

profile_path = r'C:\Users\Administrator\AppData\Roaming\Mozilla\Firefox\Profiles\y1uqp5mi.default'
options=Options()
options.set_preference('profile', profile_path)
service = Service(r'C:\WebDriver\bin\geckodriver.exe')

driver = Firefox(service=service, options=options)

driver.get("https://selenium.dev")

driver.quit()
0xC0000022L
  • 20,597
  • 9
  • 86
  • 152
Atanas Atanasov
  • 431
  • 4
  • 5
  • I copy your code and test it, and got DeprecationWarning again: 1. DeprecationWarning: firefox_profile has been deprecated, please use an Options object default_profile = FirefoxProfile(profile_path) 2. DeprecationWarning: Setting a profile has been deprecated. Please use the set_preference and install_addons methods options.profile = default_profile 3. DeprecationWarning: executable_path has been deprecated, please pass in a Service object driver = Firefox(executable_path='geckodriver.exe', options=options) I can solve the third warning, but the other two are the same. – cmy2019 Oct 15 '21 at 02:22
  • You're right, I updated the code, so there are no more deprecation warnings on my side. – Atanas Atanasov Oct 15 '21 at 10:00
  • 5
    I've copied and pasted your code changing only the paths, no deprecation warnings but the profile is not loading either, this code does not work for me. More details: https://stackoverflow.com/questions/71474700/unable-to-load-existing-firefox-profile-with-selenium-4s-option-set-preference as I'm not sure if it's just me or not. – Tyler Mar 23 '22 at 03:28
17

This error message...

firefox_profile has been deprecated, please pass in an Options object

...implies that FirefoxProfile() have been Deprecated and with to use a custom profile you have to use an instance of Options.


This DeprecationWarning was inline with the following CHANGELOGS:


All the configurations which was earlier set through profile.set_preference() now can be set through options.set_preference() as follows:

from selenium.webdriver import Firefox
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options

profile_path = r'C:\Users\Admin\AppData\Roaming\Mozilla\Firefox\Profiles\s8543x41.default-release'
options=Options()
options.set_preference('profile', profile_path)
options.set_preference('network.proxy.type', 1)
options.set_preference('network.proxy.socks', '127.0.0.1')
options.set_preference('network.proxy.socks_port', 9050)
options.set_preference('network.proxy.socks_remote_dns', False)
service = Service('C:\\BrowserDrivers\\geckodriver.exe')
driver = Firefox(service=service, options=options)
driver.get("https://www.google.com")
driver.quit()

tl; dr

Setting a custom profile

Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    This doesn't work as expected due to [this bug](https://github.com/SeleniumHQ/selenium/issues/11028). I found it to work by using the solution provided in the issue i.e. `options.add_argument("-profile")`.`options.add_argument(profile_path)` – Saifur Rahman Mohsin Dec 10 '22 at 14:31
  • "*Only give deprecation warning if Profile is being used in options*" - I'm not using a Profile, and I'm still getting this warning – leanne Mar 17 '23 at 20:02
  • My code: `driver = webdriver.Firefox(driver_path, options=options, service=service)` - and none of my options or service values include anything about the firefox profile – leanne Mar 17 '23 at 20:09
0

I tried this

from selenium.webdriver.firefox.options import Options

profile_path = r'C:\Users\Administrator\AppData\Roaming\Mozilla\Firefox\Profiles\y1uqp5mi.default'
options=Options()
options.set_preference('profile', profile_path)
driver = Firefox(options=options)
shihar
  • 48
  • 7