pythonseleniumselenium-webdriverselenium-chromedriverbrave

How to load the default brave profile with selenium?


I'm using brave browser on the operating system Pop!_OS Linux. I've seen multiple answers on the web suggesting to do it through adding an argument being the --user-data-dir and assigning the path of the default browser folder to it. I've done this using this line of code:

    options.add_argument(r"--user-data-dir=/home/sxvxge/.config/BraveSoftware/Brave-Browser/Default")

options was defined as and was used as the following:

    options = webdriver.ChromeOptions()
    options.binary_location = '/opt/brave.com/brave/brave'
    options.add_argument(r"--user-data-dir=/home/sxvxge/.config/BraveSoftware/Brave-Browser/Default")

options was also used when defining the driver:

service = Service(self.chromedriver) # self.chromedriver is the path to the chromedriver
driver : WebDriver = webdriver.Chrome(service=service, options=options)

However, when launching a browser instance with selenium, by using driver.get(), the instance wouldn't have the profile data loaded at all. I couldn't find a solution to my problem no matter what I tried. What could I do to fix this issue?

Note: All paths used in the code are valid.


Solution

  • You have to mention the profile directory path as below:

    # path of the Brave profile's parent directory
    options.add_argument("--user-data-dir=/home/sxvxge/.config/BraveSoftware/Brave-Browser/")
    # name of the directory
    options.add_argument("--profile-directory=Default")