Приветствую.
Основная проблема - selenium не запускается при уже открытом Chrome. В связи с этим, в режиме многопоточности не получается запустить несколько отдельных Chrome профилей, да и вообще более чем 1 экземпляр браузера.
Chromedriver помещен в папку с проектом и соответствует текущей версии Chrome, т.е единичный экземпляр selenium Chrome запускается без ошибок.
from selenium import webdriver
from threading import *
def driver_start(driver):
driver.get("https://www.google.com")
DRIVER = []
for i in range(1,3,1):
options = Options()
options.add_argument("user-data-dir=C:\\Users\\User\\AppData\\Local\\Google\\Chrome\\User Data")
options.add_argument(f'--profile-directory=Profile {i}')
service = Service(executable_path="chromedriver.exe")
driver = webdriver.Chrome(service=service, options=options)
DRIVER.append(driver)
for i in DRIVER:
th = Thread(target=driver_start, args=(i,))
th.start()
Ошибка выглядит следующим образом:
Traceback (most recent call last):
File "C:/Users/User/OneDrive/Рабочий стол/Python/project/main.py", line 71, in <module>
driver = webdriver.Chrome(service=service, options=options)
File "C:\Users\User\OneDrive\Рабочий стол\Python\project\venv\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 81, in __init__
super().__init__(
File "C:\Users\User\OneDrive\Рабочий стол\Python\project\venv\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 106, in __init__
super().__init__(
File "C:\Users\User\OneDrive\Рабочий стол\Python\project\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 288, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\User\OneDrive\Рабочий стол\Python\project\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 381, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "C:\Users\User\OneDrive\Рабочий стол\Python\project\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 444, in execute
self.error_handler.check_response(response)
File "C:\Users\User\OneDrive\Рабочий стол\Python\project\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 249, in check_response
raise exception_class(message, screen, stacktrace)
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\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Stacktrace:
Backtrace:
Ordinal0 [0x00518CE3+2067683]
Ordinal0 [0x004ACBC1+1625025]
Ordinal0 [0x003AB7CD+571341]
Ordinal0 [0x003CAAB3+699059]
Ordinal0 [0x003C6BF9+683001]
Ordinal0 [0x003FDBF6+908278]
Ordinal0 [0x003FD6CA+906954]
Ordinal0 [0x003F7156+880982]
Ordinal0 [0x003CFF1D+720669]
Ordinal0 [0x003D0F5F+724831]
GetHandleVerifier [0x007CF162+2771330]
GetHandleVerifier [0x007C1145+2713957]
GetHandleVerifier [0x005ACC0A+533546]
GetHandleVerifier [0x005AB970+528784]
Ordinal0 [0x004B4F4C+1658700]
Ordinal0 [0x004B98B8+1677496]
Ordinal0 [0x004B99A5+1677733]
Ordinal0 [0x004C4CC4+1723588]
BaseThreadInitThunk [0x766AFEF9+25]
RtlGetAppContainerNamedObjectPath [0x77A57BBE+286]
RtlGetAppContainerNamedObjectPath [0x77A57B8E+238]