How to use a specific Chrome profile in Python Selenium

Selenium is a Python automation module used to automate and test web applications. In this Answer, we'll learn how to use a specific Chrome profile in Selenium using Python.

Selenium opens Chrome by default in incognito mode. If we want to open it with any pre-existing settings like logins, Chrome extensions, etc., we can tell Selenium to open Chrome with a specific Chrome profile by providing details to the ChromeOptions object.

Let's take a look at an example of this.

Code example

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
#create chromeoptions instance
options = webdriver.ChromeOptions()
options.add_argument("--headless")
options.add_argument("--no-sandbox")
#provide location where chrome stores profiles
options.add_argument(r"--user-data-dir=/home/username/.config/google-chrome")
#provide the profile name with which we want to open browser
options.add_argument(r'--profile-directory=Profile 3')
#specify where your chrome driver present in your pc
driver = webdriver.Chrome(options=options)
#provide website url here
driver.get("https://omayo.blogspot.com/")
#find element using its id
print(driver.find_element("id","home").text)

Code explanation

In the above code snippet:

  • Line 5: We create an instance of the ChromeOptions class and assign it to the options variable.

  • Line 10: We provide the path where Chrome stores profiles as a value to the argument –user-data-dir.

    • In a Linux based system, Chrome stores profiles in the path /home/username/.config/google-chrome.

    • In Windows, Chrome stores profiles in the path C:\Users\your user name here\AppData\Local\Google\Chrome\User Data.

  • Line 13: We add the argument –profile-directory with value as the directory name of the Chrome profile to the options variable. Here, we specify to use Chrome Profile 3.

  • Line 16: We create an instance of a web driver and assign it to the driver variable.

  • Line 19: We open the webpage using the get() method.

  • Line 22: We find an element with the id home and display its value to test it.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved