我有一个网站可以使用硒和ChromeDriver(在Windows上)进行测试,我喜欢测试导出数据并再次导入数据的功能。
导出将创建一个xml文件,并将其下载到一台计算机上。 当使用webdriver运行此操作时,Chrome会询问我是保留该文件还是丢弃该文件,因为这可能是潜在的威胁。
如何在测试中关闭此行为? 有没有我可以使用的chrome设置,以便无论下载什么文件都可以?
谢谢
I have a website to test with selenium and ChromeDriver (on windows), where I like to test the functionality to export data and import it again.
The export creates a xml file that is downloaded on ones computer. When running this with webdriver, Chrome asks me whether to keep the file or discard it, as it might be a potential threat.
How can I switch off this behavior inside my test ? Is there a chrome setting I can use, so that a file is no matter what downloaded ?
Thanks
最满意答案
尝试这个。 在Windows上执行
( 如何在Chrome中使用Selenium Python绑定来控制文件的下载 )
from selenium import webdriver from selenium.webdriver.chrome.options import Options options = Options() options.add_experimental_option("prefs", { "download.default_directory": r"C:\Users\xxx\downloads\Test", "download.prompt_for_download": False, "download.directory_upgrade": True, "safebrowsing.enabled": True })Try this. Executed on windows
(How to control the download of files with Selenium Python bindings in Chrome)
from selenium import webdriver from selenium.webdriver.chrome.options import Options options = Options() options.add_experimental_option("prefs", { "download.default_directory": r"C:\Users\xxx\downloads\Test", "download.prompt_for_download": False, "download.directory_upgrade": True, "safebrowsing.enabled": True })更多推荐
发布评论