I'm using selenium==4.15.1 version and latest chrome web driver version 120.0.6099.71 unable to download file into specific download directory path instead it is downloading in system default downloads directory. But same code is working for another automation job and file is downloading in the specific downloading path.
def driver_conn(self, entity_tan,download_directory):
tan_path = os.path.join(os.getcwd(),"Validation","CookieFiles",entity_tan)
custom_tan_path = os.path.join(tan_path,"Default", "Cache")
download_directory = os.path.join(os.getcwd(), "Validation", "DownloadFiles")
try:
os.mkdir(tan_path)
except BaseException as e:
logger.error("tan Folder exists")
logger.info("custom dir path: {}".format(tan_path))
options = webdriver.ChromeOptions()
prefs = {
"download.default_directory": download_directory,
"download.prompt_for_download": False,
"download.directory_upgrade": True,
"safebrowsing_for_trusted_sources_enabled": False,
"safebrowsing.enabled": False}
options.add_experimental_option("prefs", prefs)
options.add_experimental_option("detach",True)
options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36")
options.add_argument("window-size=1920,1080")
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
options.add_argument('--disable-gpu')
options.add_argument('--ignore-certificate-errors')
options.add_argument('--disable-extensions')
options.add_argument("--headless")
options.add_argument('--ignore-certificate-errors-spki-list')
options.add_argument("--disable-notifications")
options.add_argument('--ignore-ssl-errors')
options.add_argument("--disable-backgrounding-occluded-windows")
options.add_argument("--disable-blink-features=AutomationControlled")
options.add_argument("user-data-dir="+custom_tan_path)
options.add_argument("--profile-directory="+entity_tan)
options.set_capability('goog:loggingPrefs', {'performance': 'ALL'})
try:
driver = webdriver.Chrome(options=options)
str1 = driver.capabilities['browserVersion']
logger.info(str1)
str2 = driver.capabilities['chrome']['chromedriverVersion']
logger.info(str2)
logger.info("Offline Webdriver found")
except BaseException as e:
logger.error("Webdriver error: {}".format(e))
return driver