I developed a simple program that executes a Chrome Driver instance using the --user-data-dir and --profile-directory from the user, such parameters are asked to the user before executing the chrome driver here:
import os
import pandas as pd
if os.name == 'nt': # Let's add some colors for the lulz
from ctypes import windll
k = windll.kernel32
k.SetConsoleMode(k.GetStdHandle(-11), 7)
import time
import re
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
opt = Options() #the variable that will store the selenium options
print('\033[34;1;4mHi Sailor! I am "Bulk-dozer", a bulk uploader built by @NoahVerner\033[0m')
print('\n')
print('\033[34;1;4mMy aim is to automate the uploading of your NFT collection to OpenSea =)\033[0m')
print('\n')
def check_path(infile):
return os.path.exists(infile)
profile_path = input('Introduce YOUR profile path:')
while True:
if check_path(profile_path) == False:
print('\033[31;1;4mThis PATH is invalid!\033[0m')
profile_path = input('Please type the RIGHT PROFILE PATH:')
elif check_path(profile_path) == True:
if r'\Google\Chrome\User Data' in profile_path:
if profile_path.split("User Data\\",1)[1] != "":
user_data = profile_path.replace(re.split('\\bUser Data\\b', profile_path)[-1], "") #get the user data path
profile_directory = profile_path.split("User Data\\",1)[1] #get the profile directory
print('\n')
break
else:
profile_path = input('\033[33;1;4mYou forgot to add the PROFILE FOLDER in the profile path, try again:\033[0m ')
else:
profile_path = input('\033[33;1;4mThe path provided does not seem to be the right one, try again:\033[0m ')
opt.add_argument(fr'--user-data-dir="{user_data}"') #Add the user data path as an argument in selenium Options
opt.add_argument(f'--profile-directory={profile_directory}') #Add the profile directory as an argument in selenium Options
s = Service('C:/Users/ResetStoreX/AppData/Local/Programs/Python/Python39/Scripts/chromedriver.exe')
driver = webdriver.Chrome(service=s, options=opt)
driver.get('https://opensea.io/login?referrer=%2Faccount')
I tested it using my profile path: C:\Users\ResetStoreX\AppData\Local\Google\Chrome\User Data\Default and got the following error:
WebDriverException: unknown error: Could not remove old devtools port file. Perhaps the given user-data-dir at "C:\Users\ResetStoreX\AppData\Local\Google\Chrome\User Data" is still attached to a running Chrome or Chromium process
Then, I made fast search looking for a command to kill all chrome/chromedriver processess on windows and found it, I immediately opened cmd and typed the following:
taskkill /F /IM chrome.exe
and got:
ERROR: Process "chrome.exe" not found.
I also typed:
taskkill /F /IM chromedriver.exe
and also got:
ERROR: Process "chromedriver.exe" not found.
The above means that there could not be any chrome instance using the user-data-dir path at the moment of executing this program, I even restarted my PC and ran this program as the very first thing and got the same WebDriverException: unknown error which is very weird.
So I think in the end the problem must be related to the way of calling user_data in opt.add_argument(fr'--user-data-dir="{user_data}"') even though this variable stores correctly the user data path and is defined as a str type:
But I haven't figured it out, so I came here to post this and look for a feedback that helps me out to solve this problem.