1

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.

Nilesh Sodha
  • 33
  • 2
  • 8

1 Answers1

3

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);
Rahul L
  • 4,249
  • 15
  • 18
  • This only works in 4.0.0 alpha version? I am trying it for 3.141.59 but it doesn't work – Ahmet Aziz Beşli Mar 06 '20 at 08:59
  • Checked with Selenium-java 3.141.59 ,geckodriver 0.26.0 (e9783a644016 2019-10-10 13:38 +0000) + FF72 . Its working fine. – Rahul L Mar 06 '20 at 11:12
  • uhh really?, I can't really add the extension. Its totally same code. – Ahmet Aziz Beşli Mar 06 '20 at 11:34
  • Can you please add more information about how you create the driver? I mean the whole code, if possible – Ahmet Aziz Beşli Mar 06 '20 at 11:59
  • `FirefoxOptions optionsFF = new FirefoxOptions(); FirefoxProfile profile = new FirefoxProfile(); profile.addExtension(new File("foxyproxy_basic-5.5-an+fx.xpi")); optionsFF.setProfile(profile); optionsFF.setLogLevel(FirefoxDriverLogLevel.TRACE);//for logs driver = new FirefoxDriver(optionsFF); ` – Rahul L Mar 06 '20 at 12:03
  • 1
    I did it, the problem was when you are trying to install your own extension and if you forgot to add application and minimum browser version tags, it won't work... – Ahmet Aziz Beşli Mar 06 '20 at 15:26
  • @AhmetAzizBeşli What is the syntax for the application and minimum browser tags? I trying to use the former code but I didn't manage to load an extension in Firefox (I'm using WebDriver 4.0.0-beta-4) – Boni García Aug 25 '21 at 17:17
  • @BoniGarcía "applications": { "gecko": { "id": "ahmet.besli@hotmail.com0", "strict_min_version": "52.0" } }, – Ahmet Aziz Beşli Aug 26 '21 at 10:40
  • @BoniGarcía https://easyupload.io/gz16ap here is a old example of mine, you can check, I was just using it to block google's urls – Ahmet Aziz Beşli Aug 26 '21 at 10:42