如何在Webdriver Chrome Profile中禁用文件下载

时间:2014-12-09 12:23:33

标签: python selenium-webdriver

我在python上使用带有Chromedriver的Webdriver。 我执行自动文件下载页面,我需要禁用它。 我需要在Chrome驱动程序下载配置文件中设置什么才能禁用自动下载?

1 个答案:

答案 0 :(得分:3)

我找到了下一个解决方案: 在CromeOption中我创建了一个无法创建的文件夹(" NUL"),因此无法下载文件,但我可以在页面上查看我需要的所有内容。

chrome_profile = webdriver.ChromeOptions()
profile = {"download.default_directory": "NUL", "download.prompt_for_download": False, }
chrome_profile.add_experimental_option("prefs", profile)
self.driver = webdriver.Chrome('chromedriver.exe',chrome_options=chrome_profile)