With Selenium on my Ubuntu EC2 instance, I'm trying to set the download directory of Chrome to /home/ubuntu/resolucion
, but the files downloaded are going to /home/ubuntu
(where my script main.py
is). I tried not using os
and just typing "download.default_directory": "/home/ubuntu/resolucion"
but still not working. The code below only works fine on my pc.
Note: there are no errors on the browser logs, neither any kind of error during script execution.
main.py
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
import os
options = webdriver.ChromeOptions()
options.add_argument("--no-sandbox")
options.add_argument("--headless")
dir_base = os.path.abspath(os.curdir)
carpeta_resolucion = os.path.join(dir_base, "resolucion")
options.add_experimental_option("prefs", {
"download.default_directory": carpeta_resolucion,
"browser.downloads.dir": carpeta_resolucion,
"directory_upgrade": True,
"download.prompt_for_download": False,
"download.extensions_to_open": "application/xml",
"safebrowsing.enabled": True
})
print(options.to_capabilities())
driver = webdriver.Chrome(service=Service(
ChromeDriverManager().install()), options=options)
This is the printed information of options.to_capabilities()
:
{'browserName': 'chrome', 'pageLoadStrategy': 'normal', 'goog:chromeOptions': {'prefs': {'download.default_directory': '/home/ubuntu/resolucion', 'browser.downloads.dir': '/home/ubuntu/resolucion', 'directory_upgrade': True, 'download.prompt_for_download': False, 'download.extensions_to_open': 'application/xml', 'safebrowsing.enabled': True}, 'extensions': [], 'args': ['--no-sandbox', '--headless']}}