【问题标题】:Running firefox with extension enabled using selenium使用 selenium 运行带有扩展名的 firefox
【发布时间】:2018-04-16 13:52:09
【问题描述】:

我使用的是 firefox 版本-59.0.2 和 selenium 版本-3.6.0。我的任务是在启用扩展的情况下在 firefox 中无头运行。我一次只能执行一项任务,即我可以运行带扩展名的无头或午餐火狐,但我无法同时执行这两项操作,因为在特定 jar 中一次不支持两者。如何这样做

System.setProperty("webdriver.firefox.bin", "C:\\Users\\rahul\\AppData\\Local\\Mozilla Firefox\\firefox.exe");
System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE, "true");
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "/dev/null");

FirefoxBinary firefoxBinary = new FirefoxBinary();
firefoxBinary.addCommandLineOptions("--headless");
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setBinary(firefoxBinary);
FirefoxDriver driver = new FirefoxDriver(firefoxOptions);

String autoFilePath = "C:\\software\\autoauth-3.1.1-an+fx.xpi";
FirefoxProfile profile = new FirefoxProfile();
profile.addExtension(new File(autoFilePath));
 FirefoxDriver driver = new FirefoxDriver(profile);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
WebDriverWait wait=new WebDriverWait(driver, 60);
driver.get("http://www.google.com");

【问题讨论】:

    标签: selenium firefox selenium-webdriver headless


    【解决方案1】:

    像这样使用firefoxOptions.setProfile(profile);

    System.setProperty("webdriver.firefox.bin", "C:\\Users\\rahul\\AppData\\Local\\Mozilla Firefox\\firefox.exe");
    System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE, "true");
    System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "/dev/null");
    
    String autoFilePath = "C:\\software\\autoauth-3.1.1-an+fx.xpi";
    FirefoxProfile profile = new FirefoxProfile();
    profile.addExtension(new File(autoFilePath));
    
    FirefoxBinary firefoxBinary = new FirefoxBinary();
    firefoxBinary.addCommandLineOptions("--headless");
    FirefoxOptions firefoxOptions = new FirefoxOptions();
    firefoxOptions.setBinary(firefoxBinary);
    firefoxOptions.setProfile(profile);
    FirefoxDriver driver = new FirefoxDriver(firefoxOptions);
    

    【讨论】:

    • 它适用于 firebug 和 firepath 插件,但是当我上传 autoauth 插件时,它给出的 errorExtension 应该包含 install.rdf 或 manifest.json 元数据文件。为什么会这样。当我手动安装插件时通过Firefox它的工作正常
    猜你喜欢
    • 2013-05-23
    • 1970-01-01
    • 2021-11-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-16
    • 2018-05-24
    相关资源
    最近更新 更多