download.default_directory as an in-memory filesystem

26 views
Skip to first unread message

life is complex

unread,
Feb 18, 2022, 3:56:30 AM2/18/22
to Selenium Users
I'm trying to use an in-memory filesystem with the download.default_directory parameter. 

I have used an in-memory filesystem with Selenium before, but never as the  download.default_directory.  So far I cannot get this to work. 

Can I use an in-memory filesystem with the download.default_directory?

Here is a snippet of my code:

import fs
import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

capabilities = DesiredCapabilities().CHROME

# Create RAMDISK
mem_fs = fs.open_fs('mem://')
mem_fs.makedir('hidden_dir')
directory_abspath = os.path.abspath(''.join(f'{str(mem_fs)}/{file_path}'))

chrome_options = Options()
chrome_options.add_argument("--disable-infobars")
chrome_options.add_argument("--start-maximized")
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument("--disable-popup-blocking")
chrome_options.add_argument("--headless")

prefs = {"download.default_directory": directory_abspath,
"download.prompt_for_download": False,
"profile.default_content_setting_values.automatic_downloads": 0,
"profile.content_settings.exceptions.automatic_downloads": 0
}

chrome_options.add_experimental_option('prefs', prefs)
capabilities.update(chrome_options.to_capabilities())

...truncated

Reply all
Reply to author
Forward
0 new messages