Biraj Raj
Biraj Raj

Reputation: 119

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?

Upvotes: 11

Views: 7483

Answers (2)

Moshe Slavin
Moshe Slavin

Reputation: 5214

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!

Upvotes: 6

Ben Antonellis
Ben Antonellis

Reputation: 789

If you're just trying to open a new browser, you can use Selenium to create a new driver with Chrome attached. You will need to download the chrome driver from here, and have it in the path as shown below.

Here is the python code:

from selenium import webdriver

driver = webdriver.Chrome("path-to-chromedriver")
driver.get("https://www.google.com/")

Upvotes: -3

Related Questions