Search code examples
pythonselenium-webdriverselenium-chromedriver

Permission Error when opening more than 3 selenium chrome driver at one time


Three driver open, but bevore the fourtht can open the following error appears:

Traceback (most recent call last):
  File "C:\Users\jan\PycharmProjects\email_creating\venv\lib\site-packages\webdriver_manager\core\file_manager.py", line 65, in __extract_zip
    archive.extractall(to_directory)
  File "C:\Users\jan\AppData\Local\Programs\Python\Python39\lib\zipfile.py", line 1642, in extractall
    self._extract_member(zipinfo, path, pwd)
  File "C:\Users\jan\AppData\Local\Programs\Python\Python39\lib\zipfile.py", line 1696, in _extract_member
    open(targetpath, "wb") as target:
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\jan\\.wdm\\drivers\\chromedriver\\win64\\115.0.5790.171\\chromedriver-win32\\chromedriver.exe'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\jan\PycharmProjects\email_creating\main.py", line 110, in <module>
    driver =webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
  File "C:\Users\jan\PycharmProjects\email_creating\venv\lib\site-packages\webdriver_manager\chrome.py", line 40, in install
    driver_path = self._get_driver_binary_path(self.driver)
  File "C:\Users\jan\PycharmProjects\email_creating\venv\lib\site-packages\webdriver_manager\core\manager.py", line 41, in _get_driver_binary_path
    binary_path = self._cache_manager.save_file_to_cache(driver, file)
  File "C:\Users\jan\PycharmProjects\email_creating\venv\lib\site-packages\webdriver_manager\core\driver_cache.py", line 54, in save_file_to_cache
    files = self.unpack_archive(archive, path)
  File "C:\Users\jan\PycharmProjects\email_creating\venv\lib\site-packages\webdriver_manager\core\driver_cache.py", line 49, in unpack_archive
    return self._file_manager.unpack_archive(archive, path)
  File "C:\Users\jan\PycharmProjects\email_creating\venv\lib\site-packages\webdriver_manager\core\file_manager.py", line 57, in unpack_archive
    return self.__extract_zip(archive_file, target_dir)
  File "C:\Users\jan\PycharmProjects\email_creating\venv\lib\site-packages\webdriver_manager\core\file_manager.py", line 81, in __extract_zip
    os.replace(source, destination)
PermissionError: [WinError 5] Access is denied: 'C:\\Users\\jan\\.wdm\\drivers\\chromedriver\\win64\\115.0.5790.171\\chromedriver-win32\\chromedriver.exe' -> 'C:\\Users\\jan\\.wdm\\drivers\\chromedriver\\win64\\115.0.5790.171\\chromedriver.exe'

This is the code that im running:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.select import Select
from webdriver_manager.chrome import ChromeDriverManager
import time

options = Options()
options.add_experimental_option("detach", True)
options.add_argument("--disable-logging")
options.add_argument("--disable-login-animations")
options.add_argument("--disable-notifications")
options.add_argument("--incognito")
options.add_argument("--ignore-certificate-errors")
options.add_argument("--disable-blink-features=AutomationControlled")

if __name__ == "__main__":
    amount = 4
    i=0
    drivers = []
    for _ in range(amount):
        driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
        drivers.append(driver)
        time.sleep(1)

If I set the amount to 1,2 or 3 it works. I tried 4, 5 and 50 and the error appeared. Thanks for your help.


Solution

  • As a comment suggested does the webdriver_manager cause the problem https://github.com/SergeyPirogov/webdriver_manager/issues/593. I tried it without the manager and it worked.