Selenium chromedriver can't open a new chrome window with user profile

2.7k Views Asked by At

Recently I've been trying to open a new chrome window with my user profile. I've got the code below:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\Users\\user_name\\AppData\\Local\\Google\\Chrome\\User Data\\")
options.add_argument("profile-directory=Profile 1")

ser = Service("C:\\path\\to\\my\\chromedriver.exe")

driver = webdriver.Chrome(service = ser,options=options)
driver.get('https://www.google.co.in/')

After running it, this error showed up:

selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited normally.
(unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location C:\Program Files (x86)\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Stacktrace:
Backtrace:
    (No symbol) [0x0031DCE3]
    (No symbol) [0x002B39D1]
    (No symbol) [0x001C4DA8]
    (No symbol) [0x001E20BC]
    (No symbol) [0x001DED19]
    (No symbol) [0x002115AE]
    (No symbol) [0x0021129C]
    (No symbol) [0x0020ACC6]
    (No symbol) [0x001E6F68]
    (No symbol) [0x001E80CD]
    GetHandleVerifier [0x00593832+2506274]
    GetHandleVerifier [0x005C9794+2727300]
    GetHandleVerifier [0x005CE36C+2746716]
    GetHandleVerifier [0x003C6690+617600]
    (No symbol) [0x002BC712]
    (No symbol) [0x002C1FF8]
    (No symbol) [0x002C20DB]
    (No symbol) [0x002CC63B]
    BaseThreadInitThunk [0x768200F9+25]
    RtlGetAppContainerNamedObjectPath [0x77017BBE+286]
    RtlGetAppContainerNamedObjectPath [0x77017B8E+238]

It only occurs if another chrome window is opened. How can I fix this?

3

There are 3 best solutions below

0
Abdul Moez On

After recent updates of chrome I am also facing this problem. Instead of this use cookies here is the usage example.

How to save and load cookies using Python + Selenium WebDriver

0
MASUM RAZA On

If you download the latest version of Chromedriver, import it into your project, and pass the driver path of Chromedriver, the issues will resolve.

0
Ambitious On

This issue is seen in the latest version of chrome. Workaround for this issue is to download the equivalent chromedriver.exe and pass it using System.setProperties. In this case WebDriverManager will not work as such.