How to load default profile in Chrome using Python Selenium Webdriver? How to load default profile in Chrome using Python Selenium Webdriver? python python

How to load default profile in Chrome using Python Selenium Webdriver?


This is what finally got it working for me.

from selenium import webdriveroptions = webdriver.ChromeOptions() options.add_argument("user-data-dir=C:\\Path") #Path to your chrome profilew = webdriver.Chrome(executable_path="C:\\Users\\chromedriver.exe", chrome_options=options)

To find path to your chrome profile data you need to type chrome://version/ into address bar . For ex. mine is displayed as C:\Users\pc\AppData\Local\Google\Chrome\User Data\Default, to use it in the script I had to exclude \Default\ so we end up with only C:\Users\pc\AppData\Local\Google\Chrome\User Data.

Also if you want to have separate profile just for selenium: replace the path with any other path and if it doesn't exist on start up chrome will create new profile and directory for it.


This solved my problem. (remove Default at the end)

from selenium import webdriveroptions = webdriver.ChromeOptions()options.add_argument("--user-data-dir=/home/username/.config/google-chrome")cls.driver = webdriver.Chrome(options=options,                              executable_path="./../ext/chromedriver")

Chrome_Options ist deprecated. Use options instead


Just to share what worked for me. Using default's profile was complicated, chrome keeps crashing.

from pathlib import Pathfrom selenium import webdriverdriver_path = Path("{}/driver/chromedriver75.exe".format(PATH_TO_FOLDER))user_data_dir = Path("{}/driver/User Data".format(PATH_TO_FOLDER))options = webdriver.ChromeOptions()# TELL WHERE IS THE DATA DIRoptions.add_argument("--user-data-dir={}".format(user_data_dir))# USE THIS IF YOU NEED TO HAVE MULTIPLE PROFILESoptions.add_argument('--profile-directory=Default')driver = webdriver.Chrome(executable_path=driver_path, options=options)driver.get("https://google.com/")

By doing this Chrome will create the folder User Data and keep all the data in it where I want and it's easy to just move your project to another machine.