gpt4 book ai didi

java - setPreference for FirefoxProfile 但无法关闭“保存”对话框

转载 作者:行者123 更新时间:2023-12-01 06:15:06 26 4
gpt4 key购买 nike

我使用 selenium 使用 Firefox 版本 30 为我的网站(称为“A”)进行自动化测试。我想将 csv 文件下载到定义的文件夹而不显示“保存”对话框。我已经设置了 FirefoxProfile 的首选项,但它不起作用。

这是我的源代码:

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.dir", screenshotFolderPath); //"C:\\Users\\Administrator\\workspace\\autoTest\\screenshot\\" + screenshotFolderName + "\\" + screenshotFileName + "\\");
profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/msword, application/csv, application/ris, text/csv, image/png, application/pdf, text/html, text/plain, application/zip, application/x-zip, application/x-zip-compressed, application/download, application/octet-stream");
profile.setPreference("browser.download.manager.showWhenStarting", false);
profile.setPreference("browser.download.manager.focusWhenStarting", false);
profile.setPreference("browser.download.useDownloadDir", true);
profile.setPreference("browser.helperApps.alwaysAsk.force", false);
profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
profile.setPreference("browser.download.manager.closeWhenDone", true);
profile.setPreference("browser.download.manager.showAlertOnComplete", false);
profile.setPreference("browser.download.manager.useWindow", false);
profile.setPreference("services.sync.prefs.sync.browser.download.manager.showWhenStarting", false);
profile.setPreference("pdfjs.disabled", true);
driver = new FirefoxDriver(profile);
driver.findElement(By.id("btn-download-log")).click();
  1. 我的源代码有问题吗?

  2. 我已在另一个网站(称为“B”)上尝试过此源代码。有效。但在我的网站(“A”)中,却没有。我的网站(“A”)的源代码有问题吗?

抱歉我的英语不好。感谢您的帮助。

最佳答案

确保您的网站源代码发回内容 header ,说明文件为 application/csv 以匹配您设置的首选项。

关于java - setPreference for FirefoxProfile 但无法关闭“保存”对话框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26771908/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com