【问题标题】:Firefox Profile Not workingFirefox 配置文件不起作用
【发布时间】:2015-05-22 10:10:00
【问题描述】:

以下是我的 Firefox 配置文件的非工作代码。

@Before

public void setUp() throws Exception {

  FirefoxProfile profile = new FirefoxProfile();

  profile.setPreference("browser.helperApps.alwaysAsk.force", false);

  profile.setPreference("browser.download.manager.showWhenStarting",false);

  profile.setPreference("browser.download.dir", "/Location");

  profile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/docx");

  driver=new FirefoxDriver(profile);

  baseUrl = "<URL>";

  driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

@Test

public void test1() throws Exception {

  driver.get("URL");

  driver.findElement(By.id("Username")).sendKeys("username");

  driver.findElement(By.id("Password")).sendKeys("Password");

  driver.findElement(By.xpath(".//*[@id='rowCell0']/td[4]/a[4]")).click();// This line of code is for Download Link on the UI

现在一旦 selenium 点击它,Firefox 将再次打开确认框,询问“打开方式”和“保存文件”。

【问题讨论】:

  • 你遇到了什么错误?
  • 没有报错,但是每次我运行这段代码,火狐点击下载链接时总是会打开确认框(但是,实际上已经写了不要打开它,直接下载点击)。我不确定我哪里出错了。

标签: firefox selenium


【解决方案1】:

请删除 profile.setPreference("browser.helperApps.alwaysAsk.force", false);

profile.setPreference("browser.download.manager.showWhenStarting",false);

尝试一下它应该可以工作...告诉我

【讨论】:

  • 您好,我现在尝试这样做,但 mozilla firefox 仍然会打开确认框以打开并保存文件。有没有其他方法可以让我们从给定的 UI 链接中下载 word 文档?
  • 将此添加到您的代码中并尝试-profile.setPreference("browser.download.folderList", 2);
【解决方案2】:

我也遇到了这个问题,它阻止了我好几天! 请确定您要下载的文件类型,然后在下面的行中使用正确的值进行配置:

profile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/docx");

您的网站源代码正在发回一个内容标题,说明该文件是 xxx 以匹配您设置的首选项。

作为参考,类型可能是:application/octet-stream、application/vnd.ms-excel、text/csv、text/plain、application/zip、application/exe、application/x-zip、application/x -zip-compressed,应用程序/下载

【讨论】:

猜你喜欢
  • 2016-04-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-08-02
  • 1970-01-01
  • 2016-09-14
  • 1970-01-01
相关资源
最近更新 更多