[🐛 Bug]: Firefox does not use the profile path when passed via options. Python
See original GitHub issueWhat happened?
It seems like firefox does not use the profile path when passed via options.
I have tried many different ways to set the profile.
Method 1 (Failing)
options.set_preference('profile', profile_path)
Method 2 (Failing)
profile = FirefoxProfile(profile_path)
options.profile = profile
Method 3 (Failing)
profile = FirefoxProfile(profile_path)
driver = webdriver.Firefox(options=options, service=service, firefox_profile=profile)
All of these methods result in a temp profile being created somewhere else. This can be verified by looking at the geckodriver.log and seeing the profile path in the command.
The only way that does seem to work is passing it as an argument
Method 4 (Working)
options.add_argument("-profile")
options.add_argument(profile_path)
Setting the profile via the arguments is the only way it seems to use the profile_path. This can be verified by looking at the geckodriver.log and seeing the profile path in the command and also looking at the profile_path folder which gets populated by a bunch of files and folders.
How can we reproduce the issue?
from selenium import webdriver
from selenium.webdriver.firefox.options import Options as FirefoxOptions
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from selenium.webdriver.firefox.service import Service as FirefoxService
profile_path = "D:\\test"
driver_path = "./src/drivers/geckodriver_win64.exe"
service = FirefoxService(driver_path)
options = FirefoxOptions()
options.add_argument("--log-level=3")
options.set_preference('profile', profile_path)
driver = webdriver.Firefox(options=options, service=service)
Relevant log output
1663163281111 geckodriver INFO Listening on 127.0.0.1:49637
1663163281617 mozrunner::runner INFO Running command: "C:\\Program Files\\Mozilla Firefox\\firefox.exe" "--marionette" "--log-level=3" "--remote-debugging-port" "49638" "--remote-allow-hosts" "localhost" "-no-remote" "-profile" "C:\\Users\\AKSHAY~1.ARA\\AppData\\Local\\Temp\\rust_mozprofileDsRaUY"
1663163282023 Marionette INFO Marionette enabled
console.warn: SearchSettings: "get: No settings file exists, new profile?" (new NotFoundError("Could not open the file at C:\\Users\\akshay.aradhya\\AppData\\Local\\Temp\\rust_mozprofileDsRaUY\\search.json.mozlz4", (void 0)))
Operating System
Windows 10
Selenium version
Python 4.4.3
What are the browser(s) and version(s) where you see this issue?
Firefox
What are the browser driver(s) and version(s) where you see this issue?
GeckoDriver 0.31.0
Are you using Selenium Grid?
No
Issue Analytics
- State:
- Created a year ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Python / Selenium / Firefox: Can't start firefox with specified ...
I've found why profile doesn't save back. Certainly, the profile passed to FirefoxProfile("myprofile/full/path") is used on the run, but, it's not saved ...
Read more >How to run Firefox when your profile is missing or inaccessible
It may be missing or inaccessible it usually means that Firefox can't find or access the profile folder. This article explains what to...
Read more >Flags — Firefox Source Docs documentation
The device must be rooted since when the app runs, files that are created in the profile, which is owned by the app...
Read more >Using HTTP cookies - MDN Web Docs
An HTTP cookie (web cookie, browser cookie) is a small piece of data that a server sends to a user's web browser. The...
Read more >Your Firefox profile cannot be loaded. It may be missing or ...
ini file lists all profiles that are registered and can be used by Firefox. If you delete profile folders yourself then you need...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Java recently stopped doing this in 7c4a0501 Though Ruby maintained a list of defaults to match what Selenium 3 was doing - https://github.com/SeleniumHQ/selenium/pull/9138
Ok, dug into this and found the location of the actual issue at least.
The problem is that the
FirefoxProfileclass was not properly updated from the switch to geckodriver. Back when we used to have our own Firefox driver and it used the extension, it was managed by FirefoxProfile class, so it needed to set default values from a manifest. This is no longer needed.Instead of just zipping the provided directory, the existing code wants to update things, and whatever it is dong to update them is breaking it. If this line gets commented out - https://github.com/SeleniumHQ/selenium/blob/trunk/py/selenium/webdriver/firefox/firefox_profile.py#L163
Then this code works as expected:
Let me try deleting a bunch of things and see if everything we want to work still works. 😃