Search code examples
pythonmultithreadingseleniumselenium-chromedriver

Python undetected_chromedriver in multithreading


I want to create multithreading program for checking pages, but I cant to launch more than one browser at a time.

import from selenium.webdriver.chrome.options import Options
import undetected_chromedriver
from threading import Thread
from time import sleep
import os
mainDir = os.path.abspath(os.curdir)

def CreateBrowser():
    chrome_options = Options()
    chrome_options.add_argument("--window-size=800,900")
    chrome_options.add_argument('--profile-directory=' + str(int(time.time())))
    driver = undetected_chromedriver.Chrome(driver_executable_path=mainDir + '\\chromedriver.exe', browser_executable_path=f'{mainDir}\\utils\chrome\GoogleChromePortable\GoogleChromePortable.exe',
options=chrome_options)

driver.get("https://google.com")
sleep(60)

driver.close()
driver.quit()

if __name__ == '__main__':
   Thread(target=CreateBrowser).start()
   Thread(target=CreateBrowser).start()

Returns:

screen


Solution

  • The problem turned out to be that I used the Portable version and it was probably recompile and the launch was chrome-portable.exe , and inside was a folder APP-bin-chrome.exe . I changed the launch path and everything started working perfectly