K L
K L

Reputation: 1371

Using the default firefox profile with selenium webdriver in python

I know similar questions have been asked before, but I've tried many times and it still doesn't work for me.

I only have a default profile in firefox (called c1r3g2wi.default) and no other profiles. I want my firefox browser to start with this profile when I launch it using the selenium webdriver. How do I do this in Python?

I did this:

fp = webdriver.FirefoxProfile('C:\Users\admin\AppData\Roaming\Mozilla\Firefox\Profiles\c1r3g2wi.default')
browser = webdriver.Firefox(fp)

But I got an error:

WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect: 
'C:\\Users\x07dmin\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\c1r3g2wi.default/*.*'

Help, or pointers in the right direction, would be very much appreciated.

Upvotes: 7

Views: 25559

Answers (3)

robertspierre
robertspierre

Reputation: 4331

As of Selenium 4.16, the correct way to open the browser with a given profile is:

from selenium import webdriver
options = webdriver.FirefoxOptions()
options.profile = webdriver.FirefoxProfile("/path/to/profile")
browser = webdriver.Firefox(options=options)

Upvotes: 2

Qasim T.S.
Qasim T.S.

Reputation: 39

Moreover, you can use double backslashes in the path:

fp = webdriver.FirefoxProfile('C:\\Users\\admin\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\c1r3g2wi.default')
browser = webdriver.Firefox(fp)

Upvotes: 3

K L
K L

Reputation: 1371

Ok, I just solved this by simply changing all the slashes in my file path from "\" to "/". Never knew this would make a difference.

C:/Users/admin/AppData/Roaming/Mozilla/Firefox/Profiles/c1r3g2wi.default

Upvotes: 9

Related Questions