【问题标题】:How to make the settings for Download in Firefox when launched using Webdriver?使用 Webdriver 启动时如何在 Firefox 中进行下载设置?
【发布时间】:2015-01-06 12:30:40
【问题描述】:

我在我的 Firefox 中为 下载 设置了这个选项。但是每次我使用 Webdriver 打开 Firefox 时,它都会设置为 Save files to 下载。因此,只要有一个文件要从 Webdriver 启动的 Firefox 下载,它就会保存到默认位置。

我该怎么做才能让它在使用 webdriver 启动时总是询问我下载位置?

【问题讨论】:

    标签: firefox selenium


    【解决方案1】:

    像这样创建一个 Firefox 配置文件:

    https://support.mozilla.org/en-US/kb/profile-manager-create-and-remove-firefox-profiles

    在此配置文件中,设置正确的下载目标。现在在您的代码中创建 Firefox 驱动程序时,使用新创建的配置文件启动它。这应该可以解决问题。

    【讨论】:

    • 这也有一个缺点,如果没有使用webdriver正常打开任何firefox实例,而我们尝试使用webdriver打开firefox,则会抛出配置文件被锁定的异常。
    【解决方案2】:

    我能够使用以下代码 sn-p 实现这一点:

    FirefoxProfile profile = new FirefoxProfile();
    profile.SetPreference("browser.download.useDownloadDir", false);
    IWebDriver driver = new FirefoxDriver(profile);
    driver.Navigate().GoToUrl("http://www.google.com");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-08-12
      • 1970-01-01
      • 2015-07-27
      • 1970-01-01
      • 2015-03-05
      • 2016-07-21
      • 2019-03-28
      相关资源
      最近更新 更多