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

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.

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");

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

Related

Getting java.lang.NullPointerException in profile.setPreference("browser.popups.showPopupBlocker", false);

System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe");
ProfilesIni profile2 = new ProfilesIni();
FirefoxProfile profile3 = profile2.getProfile("AutoProfile");
profile3.setPreference("browser.popups.showPopupBlocker", false);
profile3.setPreference("browser.download.dir", "D:\\WebDriverDownloads");
profile3.setPreference("browser.download.folderList", 2);
profile3.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;");
profile3.setPreference( "browser.download.manager.showWhenStarting", false );
profile3.setPreference( "pdfjs.disabled", true );
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setProfile(profile3);
WebDriver driver = new FirefoxDriver(firefoxOptions);
The most probhable reason you are seeing a java.lang.NullPointerException is because the Firefox Profile which you are trying to use i.e. AutoProfile doesn't exist (yet to be created) on your local system.
Solution
Before you start using the Firefox Profile AutoProfile ensure that this Firefox Profile exists in your local system. You can create a Firefox Profile manually following the instructions at Creating a new Firefox profile on Windows.
To configure auto downloads setPreference("browser.popups.showPopupBlocker", false) is not required so you can remove it.
Execute your #Test.
Here you can find a detailed discussion on how to use a new/existing Firefox Profile for your tests

How to load a specific firefox profile using Selenium webdrivermanager?

I'm trying to use webdrivermanager library to load firefox driver in my selenium tests. I'm unable to load a specific firefox profile using this library. Here is what i'm trying to do:
FirefoxDriverManager.getInstance().setup() // To instantiate the firefox driver
ProfilesIni Prof = new ProfilesIni();
FirefoxProfile profile = Prof.getProfile("C:\\Users\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\6xv9ndwh.SELENIUM");
WebDriver driver = new FirefoxDriver(profile);
But this instantiates a new driver and does not force the driver instantiated by firefoxdrivermanager to use the specific profile.
I tried using default gecko driver too that does not load the profile either. Here is the code that i'm trying:
System.setProperty("webdriver.gecko.driver", "C:\\geckodriver\\geckodriver-v0.20.0-win64\\geckodriver.exe");
ProfilesIni allProfiles = new ProfilesIni();
FirefoxProfile Profile = allProfiles.getProfile('default');
Profile.setAcceptUntrustedCertificates(true);
Profile.setAssumeUntrustedCertificateIssuer(false);
driver = new FirefoxDriver(Profile);
Can someone help me on this please?
First of all create a new firefox profile
steps for it are
1. Run this command firefox.exe -p in run window
It will show this dialog box create profile with new name and exit the window.
After that perform this command in webdriver
System.setProperty("webdriver.firefox.marionette", "Path to the exe of firefox driver");
ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile("UrProfile Name which u created");
WebDriver driver = new FirefoxDriver(myprofile);
driver.get("http://www.google.com");
Hope it may help u...
This worked for me (though not using webdrivermanager) for instantiating webdriver using Gradle:
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
capabilities.setCapability("acceptInsecureCerts", true);
driver = {new FirefoxDriver(capabilities)}

Selenium 3.6.0 & webdriver = new FirefoxDriver(capabilities) - deprecated?

Since upgrading to the latest version of Selenium the following code seems to be deprecated:
Selenium 3.6.0 & webdriver = new FirefoxDriver(capabilities) - deprecated?
Full code:
System.setProperty("webdriver.gecko.driver", Base_Page.getConstant(Constant.GECKO_DRIVER_DIRECTORY));
DesiredCapabilities capabilities=DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
webdriver = new FirefoxDriver(capabilities); //deprecated
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.
From the 3.4.1 version the FirefoxOptions should be used.
Changed the following code 'FirefoxDriver(capabilities) to firefoxOptions which uses .setCapcability()
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setCapability("marionette", true);
webdriver = new FirefoxDriver(firefoxOptions);
Try following:
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver(firefoxOptions);
You can try this line;
FirefoxOptions ffOpt = new FirefoxOptions();
ffOpt.setCapabilities("marionette", true);
WebDriver driver = new FirefoxDriver(ffOpt);

Geb: How to use Marionette instead of selenium Webdriver?

It is known issue that, Firefox version 47.0.1 is not compatible with Selenium latest version. Even Firefox is announcing to use Marionette instead. Can someone give some details instruction on how to use Marionette with Geb?
As a maven project, I tried all the version of Selenium with Geb but could not be successfull. I tried the following versions;
2.50.0
2.50.1
2.51.0
2.52.0
2.53.0
2.53.1
2.6.0
2.7.0
2.8.0
2.9.0
If this is not the right place to ask this, please guide me.
I have the next configuration in GebConfig.groovy:
firefox {
System.setProperty("webdriver.gecko.driver","path/geckodriver")
driver = {new MarionetteDriver()}
}
I am using selenium 3.0.1 and I using the -Dgeb.env=firefox system property in order to make sure it takes my Firefox configuration and it working fine for me
Regards
Download the latest version of selenium standard version 2.53.1 from selenium.hq.org.downloads and try to use the newest version of the Firefox.
With version 48 of Firefox, it looks like the only solution is using marionnette, however I have not been able to get this to work in Geb yet.
This is what I have tried in GebConfig.groovy:
environments {
firefox {
driver = {
DesiredCapabilities dc = DesiredCapabilities.firefox();
LoggingPreferences prefs = new LoggingPreferences();
prefs.enable(LogType.BROWSER, Level.WARNING);
dc.setCapability(CapabilityType.LOGGING_PREFS, prefs);
dc.setCapability("marionette", true);
String currentDir = System.getProperty("user.dir");
String marionetteDriverLocation = currentDir + "/WebDriver/wires";
System.setProperty("webdriver.gecko.driver", marionetteDriverLocation);
FirefoxProfile p = new FirefoxProfile();
p.setPreference("webdriver.gecko.driver", marionetteDriverLocation);
p.setPreference("webdriver.log.file", "/tmp/firefox_console");
p.setPreference("toolkit.telemetry.enabled", false);
p.setPreference("geo.enabled", false);
p.setPreference("plugins.update.notifyUser", false);
p.setPreference("datareporting.healthreport.service.enabled", false);
p.setPreference("datareporting.healthreport.uploadEnabled", false);
p.setPreference("datareporting.policy.dataSubmissionEnabled",false);
p.setPreference("datareporting.healthreport.service.firstRun", false);
p.setPreference("datareporting.healthreport.logging.consoleEnabled", false);
p.setPreference("reader.parse-on-load.enabled", false);
dc.setCapability(FirefoxDriver.PROFILE, p);
def driver = new FirefoxDriver(dc)
driver.manage().timeouts().pageLoadTimeout(45, TimeUnit.SECONDS)
return driver
}
It should work with any of the late Selenium versions. (everything > 2.50 not sure for earlier versions)
Marionette is an external driver, it's not included in the Selenium packages (yet?)
You need to Download the gecko driver here https://github.com/mozilla/geckodriver/releases
then point selenium to the location of the geckodriver.exe
You can do that as Nelson said before in GebConfig with:
import org.openqa.selenium.firefox.MarionetteDriver
driver = {
System.setProperty("webdriver.gecko.driver","path/geckodriver")
new MarionetteDriver()
}
to make that work you will need some dependencies in your buildscript, I'm working with gradle, yours might look different, just look into what yours need to look like on maven central
compile('info.novatec.testit:webtester-support-marionette:2.0.4') { transitive = false }
compile "org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion"
compile "org.seleniumhq.selenium:selenium-support:$seleniumVersion"
(selenium support might not be necessary for you)
If you need more help, a more specific description of where you are failing would be helpful, you can also look here for a working project (with maven):
http://seleniumsimplified.com/2016/04/how-to-use-the-firefox-marionette-driver/
public class Driver {
public FirefoxDriver getFirefoxDriver(){
System.setProperty("webdriver.gecko.driver", "./geckodriver.exe");
System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE, "true");
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "/dev/null");
FirefoxOptions options = new FirefoxOptions();
options.setHeadless(true);
return new FirefoxDriver(options);
}
}

Browser Plugin Testing With Selenium

I am writing a webapp that has a browser plugin component for both firefox and chrome. My current testing system uses a series of Selenium tests created through Selenium IDE.
Is it possible to also have selenium install, activate, and delete browser plugins for firefox and chrome (possibly other browsers as well)?
I think the biggest concern is that installing/enabling the browser plugin requires a browser restart, and I'm not sure if that would through selenium off.
The acquisition of the plugin is easily handled by visiting an internal site-link to a php-script that detects your browser.
The answer is Yes, Selenium 2 supports (remote) installation of browser extensions.
The Chrome and Firefox WebDriver support the installation of extensions, remotely. Here's sample code for Chrome and Firefox:
Chrome
File file = new File("extension.crx"); // zip files are also accepted
ChromeOptions options = new ChromeOptions();
options.addExtensions(file);
// Option 1: Locally.
WebDriver driver = new ChromeDriver(options);
// Option 2: Remotely
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
Firefox
File file = new File("extension.xpi");
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.addExtension(file);
// Option 1: Locally
WebDriver driver = new FirefoxDriver(firefoxProfile);
// Option 2: Remotely
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, firefoxProfile);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
I have also implemented automated installation of Opera and Safari extensions, and they have been merged upstream:
OperaDriver: https://github.com/operasoftware/operadriver/pull/93
SafariDriver: https://github.com/SeleniumHQ/selenium/pull/87
Opera
This API is similar to the FirefoxDriver.
File file = new File("extension.oex"); // Must end with ".oex"
OperaProfile operaProfile = new OperaProfile();
operaProfile.addExtension(file);
// Option 1: Locally
WebDriver driver = new OperaDriver(operaProfile);
// Option 2: Remotely
DesiredCapabilities capabilities = DesiredCapabilities.opera();
capabilities.setCapability("opera.profile", operaProfile);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
Safari
This API is similar to the ChromeDriver.
File file = new File("extension.safariextz");
SafariOptions options = new SafariOptions();
options.addExtensions(file);
// Option 1: Locally.
WebDriver driver = new SafariDriver(options);
// Option 2: Remotely
DesiredCapabilities capabilities = DesiredCapabilities.safari();
capabilities.setCapability(SafariOptions.CAPABILITY, options);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);
Internet Explorer
Good luck.
Short answer: no
Installing a browser extension is outside of the scope of handling in Selenium.
In Chrome, it displays a modal window that is not "clickable" with Selenium when you want to add a plugin or app. Chrome does not require restarting.
Firefox has the same kind of behaviour to prompt for extension permissions.
You can try something that resides outside of the browser to do what you want. Sikuli might do the trick.