0

Using Selenium 4, I am trying to load up my personal browser profile (including cookies), so that it can load into the websites I have previously logged in to. I am using the edge browser. When testing my code snippet, it does not seem to load my browser profile, instead creating a new one (profile 1). I've ensured that the path to the profile is the correct one.

My code snippet:

    edge_options = webdriver.EdgeOptions()
    edge_options.use_chromium = True
    edge_options.add_argument("no-sandbox")
    edge_options.add_argument("disable-dev-shm-usage")
    edge_options.add_argument("disable-features=LockProfileCookieDatabase")
    edge_options.add_argument("user-data-dir=C:\\Users\\Username\\AppData\\Local\\Microsoft\\Edge\\User Data\\Default")

    driver = webdriver.Edge(options=edge_options)
    targeturl = 'https://www.targeturl.com/'
    driver.get(targeturl)

I was expecting it to load my browser profile and then visit the target url, which should be behind a login, to confirm that it does load the cookies too.

Is there something I am missing?

2
  • Instead of specifying the profile in the user-data-dir argument, you could try setting the profile-directory argument, which would be the name of your profile and not the full path (and thus you shorten your user-data-dir up until "User Data"). I don't know if this will help.
    – Denel
    Commented Aug 7, 2024 at 21:05
  • 1
    That seems to have fixed it. At first, I was using both variables but declaring them separately and then inserting them into the argument with an fstring, which didn't work, and somehow I didn't think of doing it the way you said. Thanks a lot! Commented Aug 7, 2024 at 22:29

1 Answer 1

1

As Denel mentioned in the comment, the answer was to declare the profile name separate from its path like this:

edge_options.add_argument("user-data-dir=C:\\Users\\Username\\AppData\\Local\\Microsoft\\Edge\\User Data")`
edge_options.add_argument("profile-directoy=Default")

instead of this:

edge_options.add_argument("user-data-dir=C:\\Users\\Username\\AppData\\Local\\Microsoft\\Edge\\User Data\\Default")

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.