seleniumfirefoxselenium-webdrivergeckodriverfirefox-profile

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

Solution

  • 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