11

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?

Mark Amery
  • 143,130
  • 81
  • 406
  • 459
Biraj Raj
  • 119
  • 1
  • 6

2 Answers2

5

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!

Moshe Slavin
  • 5,127
  • 5
  • 23
  • 38
  • Thanks for your suggestion. But it's not working as I wanted. It's not showing my default browser's bookmarks and history. Please suggest further. – Biraj Raj Dec 31 '18 at 10:33
  • You can use your profile... not the default... I'll add to the answer for the general public... – Moshe Slavin Dec 31 '18 at 10:40
  • @BirajRaj I have added this to the answer: `chrome_options.add_argument('--profile-directory=Profile 1')` – Moshe Slavin Dec 31 '18 at 10:47
  • @BirajRaj I still think it would be a good idea to edit your question... this can help other people with this problem... – Moshe Slavin Dec 31 '18 at 10:49
-3

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/")
Linny
  • 818
  • 1
  • 9
  • 22