Not exactly answer to your question. But I found this link very useful.
Also, I see you are trying to include user dir options. Actually, this is not required since it creates a temporary directory while launching chromedriver.exe.
To know options for chromedriver.exe - chromedriver.exe -h is of great help.
See example below which works great at my end. Also, I prefer to use paths without spaces in windows, it helps keep things simple.
If you use --verbose instead of --log-level=INFO you will get all logs.
In the chromedriver log, you can see the default arguments given to the chromedriver.exe.
import time, os
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
exePath = './driver/chromedriver.exe'
logPath = os.path.join(os.getcwd(),'logs','chromedriver.log')
serviceArgs = ["--log-level=INFO", "--readable-timestamp", "--append-log"]
# service = Service(executable_path=exePath, log_path=logPath, service_args=serviceArgs)
service = Service(log_path=logPath, service_args=serviceArgs)
service.start()
print(service.service_url)
print(service.process.pid)
# driver = webdriver.Remote(service.service_url)
# Update to remove infobars and save password popups
options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
prefs = {"profile.password_manager_enabled": False, "credentials_enable_service": False}
options.add_experimental_option("prefs", prefs)
caps = options.to_capabilities()
driver = webdriver.Remote(service.service_url, desired_capabilities=caps)
# driver = webdriver.Remote('http://localhost:63404')
driver.get('http://www.google.com/')
driver.maximize_window()
time.sleep(3) # Let the user actually see something!
driver.get("https://github.com")
time.sleep(3)
driver.back()
time.sleep(3)
driver.close()
driver.quit()
service.stop()
service.stop() terminates the chromedriver.exe or else it will keep running in the background.
Folder structure at my end is like below:
rootDir
--driver/chromedriver.exe
--testchromedriver.py (with above code)
Also, created as killchromedriver.py file to terminate all chromedriver.exe instances in case they are running in background.
import psutil # pip install psutil
for process in psutil.process_iter():
if(process.name() == 'chromedriver.exe'):
process.terminate()
print('chromedriver.exe was running and is now terminated')
Update:
Adding options to remove the infobars and save password popups