Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛 Bug]: Failed to set preferences: unknown error when specify a profile. #14652

Closed
heckad opened this issue Oct 25, 2024 · 13 comments
Closed

Comments

@heckad
Copy link

heckad commented Oct 25, 2024

What happened?

Expected Behavior -
Firefox run withprovided profile

Actual Behavior -
Firefox is not running

How can we reproduce the issue?

from selenium import webdriver
from selenium.webdriver.firefox.options import Options

firefox_options = Options()
firefox_options.add_argument("--profile D:\\path\\to\\profile\\dir")
driver = webdriver.Firefox(options=firefox_options)

Python's traceback

Traceback (most recent call last):
  File "/app/tmp/t.py", line 24, in <module>
    driver = webdriver.Firefox(options=firefox_options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/selenium/webdriver/firefox/webdriver.py", line 71, in __init__
    super().__init__(command_executor=executor, options=options)
  File "/usr/local/lib/python3.12/site-packages/selenium/webdriver/remote/webdriver.py", line 212, in __init__
    self.start_session(capabilities)
  File "/usr/local/lib/python3.12/site-packages/selenium/webdriver/remote/webdriver.py", line 299, in start_session
    response = self.execute(Command.NEW_SESSION, caps)["value"]
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/selenium/webdriver/remote/webdriver.py", line 354, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.12/site-packages/selenium/webdriver/remote/errorhandler.py", line 229, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Failed to set preferences: unknown error

Relevant log output

1729892750450	geckodriver	INFO	Listening on 127.0.0.1:58119
1729892753487	webdriver::server	DEBUG	-> POST /session {"capabilities": {"firstMatch": [{}], "alwaysMatch": {"browserName": "firefox", "acceptInsecureCerts": true, ... .active-protocols": 3}, "args": ["--profile D:\\path\\to\\profile\\dir"]}}}}
1729892753487	geckodriver::capabilities	DEBUG	Trying to read firefox version from ini files
1729892753488	geckodriver::capabilities	DEBUG	Found version 131.0.3
1729892753488	webdriver::server	DEBUG	<- 500 Internal Server Error {"value":{"error":"session not created","message":"Failed to set preferences: unknown error","stacktrace":""}}

Operating System

Windows 11

Selenium version

python 3.12

What are the browser(s) and version(s) where you see this issue?

131.0.3

What are the browser driver(s) and version(s) where you see this issue?

GecoDriver 0.35.0

Are you using Selenium Grid?

No response

Copy link

@heckad, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!

@Delta456
Copy link
Member

The given code is incomplete.

@heckad
Copy link
Author

heckad commented Oct 26, 2024

No, that's really all except two imports (Updated messaged to add them and add python's traceback).

@navin772
Copy link
Member

Hi @heckad, I was able to reproduce this issue on a Windows machine.

Interestingly, this isn't a problem on macOS; the script worked fine, and the required profile was launched.

@Delta456
Copy link
Member

Delta456 commented Oct 28, 2024

Hi @heckad! Can you try this?

from selenium import webdriver
from selenium.webdriver.firefox.options import Options

firefox_options = Options()
firefox_options.add_argument(r"--profile D:\\path\\to\\profile\\dir")
driver = webdriver.Firefox(options=firefox_options)

EDIT: This won't fix it, please ignore.

@heckad
Copy link
Author

heckad commented Oct 28, 2024

Yer, in row string mode you can write a path without double slashes.

@heckad
Copy link
Author

heckad commented Oct 28, 2024

I have the same problem on my Linux machine and in Docker too.
Reproducible dockerfile

FROM python:3.12

# Install Firefox
ARG FIREFOX_VERSION=131.0
RUN echo "deb http://deb.debian.org/debian/ unstable main contrib non-free" >> /etc/apt/sources.list.d/debian.list
RUN apt-get update -qqy \
  && apt-get -qqy --no-install-recommends install firefox \
  && rm -rf /var/lib/apt/lists/* /var/cache/apt/* \
  && wget --no-verbose -O /tmp/firefox.tar.bz2 https://download-installer.cdn.mozilla.net/pub/firefox/releases/$FIREFOX_VERSION/linux-x86_64/en-US/firefox-$FIREFOX_VERSION.tar.bz2 \
  && apt-get -y purge firefox \
  && rm -rf /opt/firefox \
  && tar -C /opt -xjf /tmp/firefox.tar.bz2 \
  && rm /tmp/firefox.tar.bz2 \
  && mv /opt/firefox /opt/firefox-$FIREFOX_VERSION \
  && ln -fs /opt/firefox-$FIREFOX_VERSION/firefox /usr/bin/firefox

RUN pip install selenium

RUN cat <<EOF > main.py
import sys
from pathlib import Path

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

path = Path(__file__).parent / "firefox_profile"

firefox_options = Options()
firefox_options.add_argument(f"--profile {path}")
firefox_options.add_argument("--headless")
firefox_options.log.level = "trace"
driver = webdriver.Firefox(options=firefox_options, service=Service(log_output=sys.stdout))
driver.get("https://google.com")
driver.quit()
EOF

CMD ["python", "main.py"]

@pujagani
Copy link
Contributor

Have you tried using the Profile class?

def profile(self) -> Optional[FirefoxProfile]:

Can you please check if that helps?

@diemol
Copy link
Member

diemol commented Dec 23, 2024

I am closing because the OP did not reply.

@diemol diemol closed this as not planned Won't fix, can't repro, duplicate, stale Dec 23, 2024
@rayanfer32
Copy link

rayanfer32 commented Jan 12, 2025

The only way I was able to solve this issue was to replace \\ with / in the path
For example:
Replace
firefox_profile_path = "C:\\Users\rayan\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\c82gocuv.default-release"
to
firefox_profile_path = "C:/Users/rayan/AppData/Roaming/Mozilla/Firefox/Profiles/c82gocuv.default-release"

@eugene159
Copy link

eugene159 commented Jan 18, 2025

Is there any way to use specific Firefox profile when using Selenium in Windows? I tried with C# but getting the same error as topic starter.

I can get my profile either like this:

FirefoxProfileManager profileManager = new FirefoxProfileManager();
FirefoxProfile profile = profileManager.GetProfile("my_profile_name");

or like this:

FirefoxProfile profile = new FirefoxProfile("C:\path_to_my_profile";

but when I use this profile like this:

FirefoxOptions options = new FirefoxOptions();
options.Profile = profile;

_driver = new FirefoxDriver(service, options);

the last line throws an exception:

Failed to set preferences: unknown error (SessionNotCreated)

The only ugly workaround is to specify the path directly with options.AddArgument("--profile C:\path_to_my_profile");
but this ugly workaround works only if you set your profile as default. Otherwise even though it opens up with Selenium, you can't control the session.

@Axios-Service
Copy link

The below works for me

from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile

geckodriver_path = r"C:\Tools\geckodriver\geckodriver.exe"  # Ensure this path is correct or replace it

options = Options()

profile_path = r"C:\Users\.... path to the profile"
profile = FirefoxProfile(profile_path)
profile.set_preference("app.update.auto", False)
options.profile = profile

service = Service(geckodriver_path)
driver = webdriver.Firefox(service=service, options=options)

driver.get("https://www.google.com")

@eugene159
Copy link

If I add
profile.SetPreference("app.update.auto", false);
I'm getting an exception:
Preference app.update.auto may not be overridden: frozen value=False, requested value=False

In my case everything blows up pretty much instantly if I create an instance of FirefoxProfile
FirefoxProfile profile = new FirefoxProfile(profilePath);
and attach it to options
FirefoxOptions options = new FirefoxOptions();
options.Profile = profile;

The only way I can run Firefox with specific profile is to use the argument in the command line directly
options.AddArgument("-profile " + profilePath);
but it works only with the default profile, you can't switch between multiple profiles programmatically.

I read somewhere that FirefoxProfile is obsolete or depricated. Maybe this is why it's not working anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants