0

I want my program to open up the default chrome profile and then get youtube. I can make it either open youtube (in a new chrome browser), or open the default chrome profile, but not both. (And no im not running both driver variables)

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


print('starting')
print('getting driver')


exec_path= "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"               # exec path from chrome://version

profilePath= 'C:\\Users\\MyName\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 1'      #profile path from chrome://version

chromePath= 'C:\\Users\\MyName\\OneDrive\\Documents\\Python programming\\chromedriver.exe'  #path to driver



options= webdriver.ChromeOptions()

options.add_argument(profilePath)
print('options add argument...')

### Run one or the other ###
driver = webdriver.Chrome(executable_path= chromePath , options=options) #gets youtube
driver = webdriver.Chrome(executable_path= exec_path, options=options) #gets chrome profile


print('webdriver getting youtube...')
driver.get("https://www.youtube.com/")

when I run the driver line that gets the chrome profile I get the error:

Traceback (most recent call last): File "C:\Users\MyName\OneDrive\Documents\Python programming\Web automation\webAuto.py", line 24, in driver = webdriver.Chrome(executable_path= exec_path, options=options) #gets chrome profile File "C:\Users\MyName\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in init self.service.start() File "C:\Users\MyName\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 104, in start raise WebDriverException("Can not connect to the Service %s" % self.path) selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

1 Answers1

0

As per your question and your code trials if you want to open a Chrome with the customized Chrome Profile, Try using below code.

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

options = Options()
options.add_argument('C:\\Users\\MyName\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 1' )
driver = webdriver.Chrome(executable_path='C:\\Users\\MyName\\OneDrive\\Documents\\Python programming\\chromedriver.exe', chrome_options=options)
driver.get("https://www.youtube.com/")

Here you will find a detailed discussion on How to open a Chrome Profile through Python