【问题标题】:Not able set profile preferences for Firefox using Selenium(3.4.0) and geckodriver 0.16无法使用 Selenium(3.4.0) 和 geckodriver 0.16 为 Firefox 设置配置文件首选项
【发布时间】:2017-10-14 10:36:16
【问题描述】:

我最近升级到了 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); 

【问题讨论】:

    标签: python firefox selenium-webdriver geckodriver


    【解决方案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());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-01
      • 2017-10-08
      • 1970-01-01
      • 1970-01-01
      • 2017-05-29
      • 1970-01-01
      • 2016-08-28
      相关资源
      最近更新 更多