selenium: [π Bug]: Firefox does not use the profile path when passed via options. Python
What 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
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 5
- Comments: 15 (7 by maintainers)
Commits related to this issue
- Use Chrome instead for saving profile. Firefox has a problem with using saved profile. https://github.com/SeleniumHQ/selenium/issues/11028 — committed to yangziy/TwitterScraper by yangziy 3 years ago
- Use Chrome instead for saving profile. Firefox has a problem with using saved profile. https://github.com/SeleniumHQ/selenium/issues/11028 — committed to yangziy/TwitterScraper by yangziy 3 years ago
- Use Chrome instead for saving profile. Firefox has a problem with using saved profile. https://github.com/SeleniumHQ/selenium/issues/11028 — committed to yangziy/TwitterScraper by yangziy 3 years ago
- Use Chrome instead for saving profile. Firefox has a problem with using saved profile. https://github.com/SeleniumHQ/selenium/issues/11028 — committed to yangziy/TwitterScraper by yangziy 3 years ago
- Use Chrome instead for saving profile. Firefox has a problem with using saved profile. https://github.com/SeleniumHQ/selenium/issues/11028 — committed to yangziy/TwitterScraper by yangziy 3 years ago
I tried doing it with: options.set_preference(βprofileβ, β/home/asif/snap/firefox/common/.mozilla/firefox/Seleniumβ) but it does not work. I am only able to use a custom profile for Firefox with the following options configuration as in the example. Note that I previously created the Selenium profile. Please let me know and I can post the full source code of the simple example.
Example
Versions
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
This issue was closed because we did not receive any additional information after 14 days.
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. π