John Doe
John Doe

Reputation: 11

Unable to load custom profile in FirefoxDriver : The constructor FirefoxDriver(FirefoxProfile) is undefined

I am trying to handle multiple popup blocker in www.naukri.com; For this I have created a custom profile in firefox naming "AutoProfile". But I am having an issue with loading this custom profile in firefox driver;

System.setProperty("webdriver.gecko.driver", "F:\\abc\\geckodriver-v0.18.0-win64\\geckodriver.exe");
ProfilesIni profile2=new ProfilesIni();
FirefoxProfile profile3=profile2.getProfile("AutoProfile");
profile3.setPreference("browser.popups.showPopupBlocker", false);
driver =new FirefoxDriver(profile3);
driver.get("www.naukri.com");

But I am getting an error in driver=new FirefoxDriver(profile3); It says:

The constructor FirefoxDriver(FirefoxProfile) is undefined. 

Some times I get a message as constructor is deprecated.

Upvotes: 1

Views: 2200

Answers (2)

Davide Patti
Davide Patti

Reputation: 3461

What are the version of Selenium and the Geckodriver that are you using?

From https://raw.githubusercontent.com/SeleniumHQ/selenium/master/rb/CHANGES

3.4.1 (2017-06-13)
==================
Firefox:
  * Added new Firefox::Options class that should be used to customize browser
    behavior (command line arguments, profile, preferences, Firefox binary, etc.).
    The instance of options class can be passed to driver initialization using
    :options key. Old way of passing these customization directly to driver
    initialization is deprecated.

In order to set the profile, you should do something like this:

         System.setProperty("webdriver.gecko.driver", "F:\\abc\\geckodriver-v0.18.0-win64\\geckodriver.exe");
        ProfilesIni profile2 = new ProfilesIni();
        FirefoxProfile profile3 = profile2.getProfile("AutoProfile");
        profile3.setPreference("browser.popups.showPopupBlocker", false);

        FirefoxOptions firefoxOptions = new FirefoxOptions();
        firefoxOptions.setProfile(profile3);

        WebDriver driver = new FirefoxDriver(firefoxOptions);
        driver.get("www.naukri.com"); 

Upvotes: 1

Zakaria Shahed
Zakaria Shahed

Reputation: 2697

The issue is due to older selenium version coexisted. mvn clean install resolved the issue.

Update gecko driver and library

Hope your problem will be solved

Upvotes: 0

Related Questions