seleniumselenium-webdriverfirefox-addonfirefox-headless

How to add extension in firefox driver in Java using selenium


How to add extension in firefox driver in selenium in Java

Have tried below possibilities.

1st tried Solution

FirefoxOptions firefoxOptions = new FirefoxOptions();
FirefoxProfile profile = new FirefoxProfile();
profile.addExtension(new File("/usr/local/bin/foxyproxy_standard-6.6.2-an+fx.xpi"));
profile.setPreference("extensions.firebug.currentVersion", "1.8.1");
firefoxOptions.setProfile(profile);
WebDriver firefoxDriver = new FirefoxDriver(firefoxOptions);

It is not giving any error but it is starting without any extension.

Used dependancy

    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-java</artifactId>
      <version>3.12.0</version>
    </dependency>
    <dependency>
      <groupId>io.github.bonigarcia</groupId>
      <artifactId>webdrivermanager</artifactId>
      <version>3.2.0</version>
    </dependency>

2nd tried Solution

FirefoxProfile profile = new FirefoxProfile();
profile.addExtension(new File("/usr/local/bin/foxyproxy_standard-6.6.2-an+fx.xpi"));
profile.setPreference("extensions.firebug.currentVersion", "1.8.1");
WebDriver firefoxDriver = new FirefoxDriver(profile);

It is also not giving any error but it is starting without any extension.

Used dependancy

    <dependency>
      <groupId>org.seleniumhq.selenium</groupId>
      <artifactId>selenium-java</artifactId>
      <version>3.0.0-beta4</version>
    </dependency>
    <dependency>
      <groupId>io.github.bonigarcia</groupId>
      <artifactId>webdrivermanager</artifactId>
      <version>3.2.0</version>
    </dependency>

3rd tried Solution

Created manually profile from firefox. 1. Open default firefox 2. about:prfiles 3. Created new profile as 'TestProfile' 4. Launch profile in new browser 5. Add some add ons 6. Close browser 7. And then execute below code.

    ProfilesIni profilesIni = new ProfilesIni();
    FirefoxOptions firefoxOptions = new FirefoxOptions();
    FirefoxProfile profile = profilesIni.getProfile("TestProfile");
    firefoxOptions.setProfile(profile);
    WebDriver firefoxDriver = new FirefoxDriver(firefoxOptions);

This is also not working

I have tried with chrome driver also it is working fine but chromedriver does not have extension support in headless mode so need to use firefox webdriver.

I have tried all solution are given already but none of them is working

So please guid me what to do.


Solution

  • Try with FF68,selenium-java 4.0.0-alpha-2 and v0.24.0 . Tested on Windows machine.

    FirefoxProfile profile = new FirefoxProfile();
    
    profile.addExtension(new File("foxyproxy_basic-5.5-an+fx.xpi"));
    
    options.setProfile(profile);