Selenium will not load my default Chrome Profile and I cannot figure out why. I have tried both Profile 1 and a Default profile with the same error (below). I have confirmed with Task Manager that all Chrome windows are shut down before running this code. Any thoughts?
from selenium import webdriver
from bs4 import BeautifulSoup
import pandas as pd
import numpy as np
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
import os
os.system("taskkill /f /im geckodriver.exe /T")
os.system("taskkill /f /im chromedriver.exe /T")
os.system("taskkill /f /im IEDriverServer.exe /T")
os.system("taskkill /f /im chrome.exe /T")
driver2 = r"C:Usersxxx.wdmdriverschromedriver87.0.4280.20win32chromedriver.exe"
options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\Usersxxx\AppData\Local\Google\Chrome\User Data\Profile 1")
driver = webdriver.Chrome(executable_path=driver2, chrome_options=options)
driver.get("https://www.google.co.in")
Traceback (most recent call last):
File "C:UsersxxxOneDrivePythonpyReportRun.py", line 16, in <module>
driver = webdriver.Chrome(ChromeDriverManager().install(), options=options)
File "C:Python38libsite-packagesseleniumwebdriverchromewebdriver.py", line 76, in __init__
RemoteWebDriver.__init__(
File "C:Python38libsite-packagesseleniumwebdriver
emotewebdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "C:Python38libsite-packagesseleniumwebdriver
emotewebdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:Python38libsite-packagesseleniumwebdriver
emotewebdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:Python38libsite-packagesseleniumwebdriver
emoteerrorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Could not remove old devtools port file. Perhaps the given user-data-dir at C:UsersxxxAppDataLocalGoogleChromeUser DataProfile 1 is still attached to a running Chrome or Chromium process
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…