Chrome keep asking me for a download location on Selenium Hub/Driver on Python

末鹿安然 提交于 2019-12-11 17:52:29

问题


I'm trying to download a couple of files in a test that are randomly generated on the back-end with a unique name

I use this preferences that I pass to the chrome driver both directly or in a selenium hub

CHROME_PREFERENCES = {
    "profile.default_content_settings.popups": 0,
    "download.prompt_for_download": "false",
    "download.directory_upgrade": "true",
    "download.default_directory": "/mnt/hgfs/down/",
    "profile.default_content_setting_values.notifications": 2,
    "profile.default_content_setting_values.automatic_downloads": 1
}

But Chrome keeps asking me for the download location every time that I make the get call to the download URL from the driver, rendering the automation useless...

I also tried, using bool values as True / False instead of "true" / "false"


回答1:


This works for me:

options = Options()
prefs = {'download.prompt_for_download': False,
        'download.default_directory': download_dir,
        'download.directory_upgrage': True,
        'profile.default_content_settings.popups': 0,
        }
options.add_experimental_option('prefs', prefs)

p.s. Sorry, i couldn't comment, so I ask here: How do you pass your preferences?



来源:https://stackoverflow.com/questions/49053624/chrome-keep-asking-me-for-a-download-location-on-selenium-hub-driver-on-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!