tryingHard
tryingHard

Reputation: 2084

How to change firefox profile preference fields like “security.insecure_field_warning.contextual.enabled” in JAVA

Firefox Version

53.0 (32-bit)

Selenium 3.4.0

    ProfilesIni profile = new ProfilesIni();
    FirefoxProfile firefoxProfile = profile.getProfile("Selenium");

    firefoxProfile.setPreference("security.insecure_field_warning.contextual.enabled", false);

The problem is the third line does nothing. If i set manaully security.insecure_field_warning.contextual.enabled to false in about:config this change is not saved in profile.

How can i set it to false from code in java ?

I saw similiar topic but it was in Python.

Obviously security.insecure_field_warning.contextual.enabled is setting from about:config in Firefox

Upvotes: 0

Views: 1028

Answers (1)

undetected Selenium
undetected Selenium

Reputation: 193208

Here is the Answer to your Question:

While working with Selenium 3.4.0 with geckodriver v.0.16.1 & Mozilla Firefox 53.x to start with a existing Firefox profile with security.insecure_field_warning.contextual.enabled set to false you need to specify ("security.insecure_field_warning.contextual.enabled", false) through setPreference and next you need to pass the Firefox profile through DesiredCapabilities Class.

Here is the working code block which sets "security.insecure_field_warning.contextual.enabled" to false in the Firefox browser:

    System.setProperty("webdriver.gecko.driver", "C:\\your_directory\\geckodriver.exe");
    ProfilesIni profile = new ProfilesIni();
    FirefoxProfile testprofile = profile.getProfile("debanjan");
    testprofile.setPreference("security.insecure_field_warning.contextual.enabled", false);
    DesiredCapabilities dc = DesiredCapabilities.firefox();
    dc.setCapability(FirefoxDriver.PROFILE, testprofile);
    dc.setCapability("marionette", true);
    WebDriver driver =  new FirefoxDriver(dc);
    driver.manage().window().maximize();

Let me know if this Answers your Question.

Upvotes: 1

Related Questions