如何在 Firefox 中编辑 anonymous/default 配置文件?

How to edit the anonymous/default profile in firefox?

我正在使用 Selenium 自动执行下载文件的测试用例。 在 Firefox 中,当我单击 link 下载文件时,会出现一个用于保存或打开文件的对话框。我转到 Firefox 并在地址栏中键入 about:config 并使用 mimetype 更新了 browser.helperapps.neverask.savetodisk。当我手动点击link下载文件时,它自动下载,没有对话框。当我使用 Selenium 将其自动化时,会出现对话框。任何人都可以建议一种在 Firefox 中自动执行此操作而无需在代码中创建配置文件的方法。我不介意更改浏览器设置。在 Firefox 中如何更新 Selenium 使用的配置文件?

在 Selenium WebDriver 中启动 firefox 时,它会启动新的匿名配置文件,您可以通过创建新配置文件和更新首选项或使用现有配置文件来修改它

FirefoxProfile profile = new FirefoxProfile(); 

profile.setPreference("browser.download.folderList", 2);

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

profile.setPreference("browser.download.dir", **enter your download path**);

profile.setPreference("browser.helperApps.neverAsk.openFile",
            "text/csv, application/pdf, application/x-msexcel,application/excel,application/x-excel,application/excel,application/x-excel,application/excel,application/vnd.ms-excel,application/x-excel,application/x-msexcel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml,application/excel");

profile.setPreference("browser.helperApps.neverAsk.saveToDisk",
            "text/csv, application/pdf, application/x-msexcel,application/excel,application/x-excel,application/excel,application/x-excel,application/excel, application/vnd.ms- excel,application/x-excel,application/x-msexcel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml,application/excel,text/x-c");

Webdriver driver = new FirefoxDriver(profile);

如果您不想在代码中创建 firefox 配置文件,请手动创建具有上述设置的 firefox 配置文件,并使用以下代码使用它

ProfilesIni all_profiles = new ProfilesIni();
FirefoxProfile profile = all_profiles.getProfile("created profile");
WebDriver driver = new FirefoxDriver(profile);

希望对您有所帮助....