1

I've encountered a problem with specifying the capabilities driver should meet. I need a browser instance to have pop ups blocked. (must have)

Capabilities code:

DesiredCapabilities caps = DesiredCapabilities().firefox();

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("dom.popup_maximum", 0);

caps.setCapability(FirefoxDriver.PROFILE, profile);

The code for creating driver:

WebDriver driver1 = new FirefoxDriver(caps);              // this one works
WebDriver driver2 = new RemoteWebDriver(properUrl, caps); // this one does not

By does work / does not work I mean, that driver1 has the pop ups blocked as it should and the driver2 allows pop ups when it should not.

The connection to grid hub is correct, because the driver does work, but unfortunately settings are not set the way they suppose to be.

Could anyone help me out please?

Adrian
  • 15
  • 3

1 Answers1

0

Use FirefoxOptions to customize the preferences:

FirefoxOptions options = new FirefoxOptions();
options.addPreference("dom.popup_maximum", 0);

WebDriver driver = new RemoteWebDriver(new URL("http://127.0.0.1:4444/wd/hub"), options);
Florent B.
  • 41,537
  • 7
  • 86
  • 101
  • It worked! Thank you a lot! Could you explain the difference between FirefoxOptions way and FirefoxProfile way a bit more? – Adrian Nov 09 '17 at 16:43
  • `FirefoxProfile` is a legacy class used to build a profile physically on the drive. It should no longer be used. `FirefoxOptions` is a class introduced by the geckodriver which behaves more or less like `ChromeOptions` by sending the capabilities directly to the driver. – Florent B. Nov 09 '17 at 16:56