我正在尝试保存图像文件(jpeg)而不要求通过右键单击图像点击“另存为”选项确认保存图像。
设置了firefox配置文件的已知属性后,仍会出现确认对话框,可以找到解决方案。
但是,使用相同的属性,excel的打开文件可以正常工作。
fxProfile.setPreference("browser.download.folderList", 2);
fxProfile.setPreference("browser.download.manager.showWhenStarting",false);
fxProfile.setPreference("browser.download.dir", "D:\\mydownloads\\");
fxProfile.setAcceptUntrustedCertificates(true);
fxProfile.setPreference("browser.helperApps.alwaysAsk.force", false);
fxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/octet-stream");
fxProfile
.setPreference(
"browser.helperApps.neverAsk.openFile",
"text/csv, application/pdf, application/x-msexcel,application/excel,application/x-excel,application/vnd.ms-excel,application/x-excel,application/x-msexcel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml");
fxProfile
.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/pjpeg,image/jpeg,text/html,text/plain,application/msword,application/xml,application/excel");
WebDriver driver = new FirefoxDriver(fxProfile);
硒 - 服务器 - 独立-2.45.0.jar
java版“1.8.0_31”
答案 0 :(得分:0)
browser.helperApps.neverAsk.saveToDisk
。browser.helperApps.neverAsk.openFile
PHP中的工作代码示例(无论语言如何,设置都相同):
$profile = new FirefoxProfile();
$profile->setPreference('browser.download.folderList', 2); # download to dir
$profile->setPreference('browser.download.panel.shown', false); # don't show info bubble
$profile->setPreference('browser.download.dir', '/tmp');
$profile->setPreference('browser.helperApps.neverAsk.openFile', 'application/x-octet-stream,text/csv'); # skip confirm
$capabilities->setCapability(FirefoxDriver::PROFILE, $profile);