Selenium: Point towards default Chrome session

Make sure you are pointing to the right folder using "Chrome://version".

enter image description here

I am using the windows but it should be similar in you mac case too.

Refer to this link for more information.

How to create a custom profile:

You can create your own custom profile by just running Chrome (on the command-line or through ChromeDriver) with the user-data-dir switch set to some new directory. If the path doesn't exist, Chrome will create a new profile in the specified location. You can then modify the profile settings as desired, and ChromeDriver can use the profile in the future. Open chrome://version in the browser to see what profile Chrome is using.

Reference:

http://chromedriver.chromium.org/capabilities


To start with, No, you can't point (hook up) the Selenium driver to any of the existing/previous Web Browsing session. Even if you are able to extract the Session ID, Cookies and other session attributes from the existing/previous Web Browsing session, still you won't be able to pass those attributes as a HOOK to the WebDriver.

You can find a detailed discussion in How can I reconnect to the browser opened by webdriver with selenium?

But of coarse you can connect to the existing Default Chrome profile.


You seem to be already aware that trying to use the Default Chrome Profile for Test Automation will be against all the best practices as the Default Chrome Profile may contain either/all of the following:

  • browser settings
  • Extensions
  • Bookmarks
  • Apps
  • Saved Passwords
  • Browsing History
  • etc

So the Default Chrome Profile may not be in compliance with you Test Specification and may occasionally raise exception while trying to load. Hence you should always use a customized Chrome Profile.

You can find a detailed discussion in How to open a Chrome Profile through --user-data-dir argument of Selenium

If your usecase still warrants to use the Default Chrome Profile you need to follow the below mentioned details.


Location of Default Chrome Profile

As per the documentation in How to Find Your Chrome Profile Folder on Windows, Mac, and Linux the location for Chrome’s default profile folder differs depending on your platform. The locations are:

  • Windows 7, 8.1, and 10: C:\Users\<username>\AppData\Local\Google\Chrome\User Data\Default
  • Mac OS X El Capitan: Users/<username>/Library/Application Support/Google/Chrome/Default
  • Linux: /home/<username>/.config/google-chrome/default

You need to replace <username> with the name of your user folder. The default profile folder is simply named Default (or default in Linux). However, if you’ve created additional profiles, their folder names are not as obvious. The name you assigned to the profile when you created it displays on a name button on the right side of the title bar on the Chrome window. Unfortunately, the name Chrome uses on the associated profile folder is a generic, numbered name like Profile 3.

If you need to know any of the Chrome Profile's folder name, you simply need to access chrome://version in the address bar and press Enter.

Snapshot:

DefaultChromeProfile

The Profile Path shows the location of the current profile. For example, the location of my Default profile in my Windows 10 system is C:\Users\Soma Bhattacharjee\AppData\Local\Google\Chrome\User Data\Default. You can select the path and copy it and paste it into File Explorer in Windows, the Finder on OS X or into a file manager like Nautilus in Linux to access that folder.


Sample Code (Windows 10)

Finally, to access the Default Chrome Profile you can use the following Python based solution:

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

options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\Users\\Soma Bhattacharjee\\AppData\\Local\\Google\\Chrome\\User Data\\Default")
driver = webdriver.Chrome(executable_path=r'C:\WebDrivers\chromedriver.exe', chrome_options=options)
driver.get("https://www.google.co.in")

You can find a detailed discussion in How to use Chrome Profile in Selenium Webdriver Python 3