0

I'm trying to launch a Firefox profile with add-ons in it, with selenium v3.12 and gecko-driver v2.10 and Firefox version 60.0, how-ever it seems that the custom profile is not working. below is my code

  static WebDriver driver;
    ProfilesIni profile = new ProfilesIni();
            myprofile = profile.getProfile("AutoProfile");
    System.setProperty("webdriver.gecko.driver", 
      "E:\\Library\\geckodriver-v0.21.0-win32\\geckodriver.exe");
            driver = new FirefoxDriver(myprofile);

The acutal error is on the

     driver = new FirefoxDriver(myprofile);

as

The constructor FirefoxDriver(FirefoxProfile) is undefined

1
  • Are you using maven? If yes, can you post your dependencies?
    – Alexey R.
    Aug 3, 2018 at 9:17

4 Answers 4

0

Try this below line

WebDriver driver = new FirefoxDriver(myProfile);
1
  • updated the Question Aug 3, 2018 at 6:44
0

In the code you need to initialize Firefox profile with the object of myprofile.

ProfilesIni profile = new ProfilesIni();
       FirefoxProfile myprofile = profile.getProfile("AutoProfile");
    System.setProperty("webdriver.gecko.driver", 
      "E:\\Library\\geckodriver-v0.21.0-win32\\geckodriver.exe");
         WebDriver driver = new FirefoxDriver(myprofile);

Also It's a bad practise to declare the WebDriver as static. Please refer the following link for more information.

2
  • I tried above, still same error occurs Aug 3, 2018 at 7:12
  • Check the geckodriver path and update it correctly. Aug 3, 2018 at 7:18
0

Try below code, it worked for me:

    System.setProperty("webdriver.gecko.driver", "Path of geckodriver.exe on your machine");

    ProfilesIni profile = new ProfilesIni();

    FirefoxProfile myprofile = profile.getProfile("Your Firefox Profile name");

    FirefoxOptions options=new FirefoxOptions().setProfile(myprofile);

    WebDriver driver=new FirefoxDriver(options);

    driver.get("Your application URL");
0

Based on the error message mentioned in the question description, it seems like the issue is with the constructor that you are using to create the Firefox driver object.

To resolve this issue, you can try using the FirefoxOptions class instead of the FirefoxDriver class to launch the Firefox browser with a custom profile. Below is a code snippet that shows how to create a custom Firefox profile and launch the browser using the FirefoxOptions class in Java:

import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxOptions; import org.openqa.selenium.firefox.FirefoxProfile;

public class LaunchFirefoxCustomProfile {

public static void main(String[] args) {
    
    // Define path to Firefox profile
    String profilePath = "C:\\Users\\user\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\myprofile";
    
    // Create Firefox profile object
    FirefoxProfile profile = new FirefoxProfile(profilePath);
    
    // Create Firefox options object and set profile
    FirefoxOptions options = new FirefoxOptions();
    options.setProfile(profile);
    
    // Set geckodriver path
    System.setProperty("webdriver.gecko.driver", "E:\\Library\\geckodriver-v0.21.0-win32\\geckodriver.exe");
    
    // Launch Firefox browser with custom profile
    WebDriver driver = new FirefoxDriver(options);
    
    // Navigate to a website
    driver.get("https://www.example.com");
}

}

In the code above, we first define the path to the Firefox profile that we want to use. Then, we create a FirefoxProfile object using this path. Next, we create a FirefoxOptions object and set the profile using the setProfile() method. Finally, we launch the Firefox browser using the FirefoxOptions object.

I hope this helps! If you would like to learn more about launching Firefox with a custom profile using geckodriver, I recommend checking out the following resources:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.