WebDriver-是否要更改默认下载位置? [英] WebDriver - Anyway to change default download location?
本文介绍了WebDriver-是否要更改默认下载位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Selenium-webdriver + java来自动化我的应用程序.
I am using Selenium-webdriver + java for automating my application.
是否可以通过Webdriver/所需功能/任何其他方法来更改浏览器的默认下载位置"?
Is there any way to change the default "Download Location" of a Browser via Webdriver / Desired capabilities / any other approach?
推荐答案
可以通过将browser.download.folderList
的首选项值设置为2
来将下载位置更改为自定义下载路径,如下所示:
Download location can be changed to custom download path by setting preference value to 2
for browser.download.folderList
like following:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.dir", "directory_path_to_save_file");
这样做,您可以在创建配置文件时将文件下载到您提到的目录中.
By doing so, you can download file in the directory you mentioned while creating profile.
然后,通过传递profile
创建浏览器实例:
And then, create a browser instance by passing profile
:
WebDriver driver = new FirefoxDriver(profile);
这篇关于WebDriver-是否要更改默认下载位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文