Selenium loads profile only in the deprecated way (Python)

1k Views Asked by At

I tried the recommended method of loading a profile, but it's not working for me. It simply opens an empty profile.

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'E:/Python/seleniumProfile'
options=Options()
options.set_preference('profile', profile_path)
driver = Firefox(options=options)
driver.get("https://www.google.com")

No warning or error message is given, even if I type an invalid folder as the profile_path.

Old way works great, but gives the deprecation warning:

fp = webdriver.FirefoxProfile('E:/Python/seleniumProfile')
driver = webdriver.Firefox(fp)
driver.get("https://www.google.com")

DeprecationWarning: firefox_profile has been deprecated, please use an Options object

I guess I can live with the warnings, but any help would be appreciated.

1

There are 1 best solutions below

2
On

This error message...

firefox_profile has been deprecated, please pass in an Options object

...implies that usage of FirefoxProfile() have been Deprecated and with and to use a custom profile you have to use an instance of Options . This DeprecationWarning was inline with the following CHANGELOGS:


Solution

To use an existing firefox profile you can use the following solution:

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)
service = Service('C:\\BrowserDrivers\\geckodriver.exe')
driver = Firefox(service=service, options=options)
driver.get("https://www.google.com")

tl; dr

Setting a custom profile