无法使用Selenium(3.4.0)和geckodriver 0.16为Firefox设置配置文件首选项



我最近升级到FireFox 53.0.3,Gecko驱动程序0.16.1和Selenium 3.4.0。在此升级之前,我的代码在下面工作正常。升级后,当我尝试设置配置文件首选项时出现错误。有人可以告诉我有什么替代方案,或者我在哪里可以找到替代方案?我确实阅读了现有问题 - 无法使用Selenium(壁虎驱动程序0.16(设置Firefox配置文件的首选项,但是我被困在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); 

发布这个答案是因为我花了很多时间来解决这个问题。我尝试使用FirefoxOptions类,它对我有用。当浏览器打开时,我检查了关于:配置页面中的首选项,设置是否正确完成。

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());

相关内容

最新更新