【发布时间】:2015-01-06 12:30:40
【问题描述】:
我在我的 Firefox 中为 下载 设置了这个选项。但是每次我使用 Webdriver 打开 Firefox 时,它都会设置为 Save files to 下载。因此,只要有一个文件要从 Webdriver 启动的 Firefox 下载,它就会保存到默认位置。
我该怎么做才能让它在使用 webdriver 启动时总是询问我下载位置?
【问题讨论】:
我在我的 Firefox 中为 下载 设置了这个选项。但是每次我使用 Webdriver 打开 Firefox 时,它都会设置为 Save files to 下载。因此,只要有一个文件要从 Webdriver 启动的 Firefox 下载,它就会保存到默认位置。
我该怎么做才能让它在使用 webdriver 启动时总是询问我下载位置?
【问题讨论】:
像这样创建一个 Firefox 配置文件:
https://support.mozilla.org/en-US/kb/profile-manager-create-and-remove-firefox-profiles
在此配置文件中,设置正确的下载目标。现在在您的代码中创建 Firefox 驱动程序时,使用新创建的配置文件启动它。这应该可以解决问题。
【讨论】:
我能够使用以下代码 sn-p 实现这一点:
FirefoxProfile profile = new FirefoxProfile();
profile.SetPreference("browser.download.useDownloadDir", false);
IWebDriver driver = new FirefoxDriver(profile);
driver.Navigate().GoToUrl("http://www.google.com");
【讨论】: