Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use default Chrome profile with Selenium in Python

When I launch Chrome with Selenium like this...

from selenium import webdriver
driver = webdriver.Chrome("/path/to/chromedriver")

... I get a "clean" Chrome instance with no browsing history and none of my stored data from the normal installation of Chrome on my computer.

I want to open Chrome with Selenium but have the bookmarks, history, cookies, cache, etc. from my default Chrome installation available in the opened browser.

How can I do this?

like image 781
Biraj Raj Avatar asked Dec 30 '18 06:12

Biraj Raj


1 Answers

You can use a specific profile or the default one as in your question:

How to open a new Default Browser Window in Chrome using Selenium in Python?

Here is a snip of a set up:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument("--user-data-dir=THE/PATH/TO/YOUR/PROFILE") # change to profile path
chrome_options.add_argument('--profile-directory=Profile 1')

browser = webdriver.Chrome(executable_path="PATH/TO/cromedriver.exe", chrome_options=chrome_options) # change the executable_path too

To find the path to the profile just type chrome://version/ in your default chrome browser and you will see it under Profile Path: in my PC it's "C:\Users\user\AppData\Local\Google\Chrome\User Data\Default"

Hope you find this helpful!

like image 59
Moshe Slavin Avatar answered Nov 18 '22 02:11

Moshe Slavin