我最近升级到FireFox 53.0.3,Gecko驱动程序0.16.1和Selenium 3.4.0。我的代码在升级之前工作正常。升级后,当我尝试设置配置文件首选项时,我收到错误。有人可以告诉我可以替代这个或者在哪里可以找到替代品吗?我确实阅读了现有的问题 - unable to set preferences for Firefox profile with Selenium (geckodriver 0.16),但我仍然坚持在Geckodrive中替换这些问题。
profile.setPreference("webdriver.load.strategy", "unstable");
profile.setAssumeUntrustedCertificateIssuer(false);
profile.setPreference("browser.download.dir", "C:\\Firefox");
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.helperApps.neverAsk.openFile",
"text/csv,application/x-msexcel,application/excel,application/ms-excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml");
profile.setPreference("browser.helperApps.neverAsk.saveToDisk",
"text/csv,application/x-msexcel,application/excel,application/ms-excel,application/x-excel,application/vnd.ms-excel,image/png,image/jpeg,text/html,text/plain,application/msword,application/xml");
profile.setPreference("browser.helperApps.alwaysAsk.force", false);
profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
profile.setPreference("browser.download.manager.focusWhenStarting", false);
profile.setPreference("browser.download.manager.useWindow", false);
profile.setPreference("browser.download.manager.showAlertOnComplete", false);
profile.setPreference("browser.download.manager.closeWhenDone", false);
答案 0 :(得分:1)
发布此答案是因为我花了很多时间来弄清楚这个问题。我尝试使用FirefoxOptions类,它对我有用。当浏览器打开时,我检查了about:config页面中的首选项,并且设置正确完成。
FirefoxOptions options = new FirefoxOptions();
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("webdriver.load.strategy", "unstable");
profile.setAssumeUntrustedCertificateIssuer(false);
profile.setPreference("browser.download.dir", "C:\\download");
profile.setPreference("browser.download.folderList", 2);
options.setProfile(profile);
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options);
WebDriver driver = new FirefoxDriver(capabilities);
driver.get("http://www.google.com");
System.out.println("Title====" + driver.getTitle());