简体   繁体   中英

unable to launch FireFox custom profile with geckodriver in java

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 line

driver = new FirefoxDriver(myprofile);

as

The constructor FirefoxDriver(FirefoxProfile) is undefined

You have to pass it through firefox options.

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

If the below solution causes a java heap error, you could try DesiredCapabilities, like this:

System.setProperty("webdriver.gecko.driver","E:\\Library\\geckodriver-v0.21.0-win32\\geckodriver.exe");
File file = new File(path_to_your_firefox_profile);
DesiredCapabilities dc = DesiredCapabilities.firefox();
FirefoxProfile profile = new FirefoxProfile(file);
dc.setCapability(FirefoxDriver.PROFILE, profile);
FirefoxDriver driver = new FirefoxDriver(dc);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM