1

When using Java and Selenium, frequently when I google how to change a certain behaviour I find some example that explains how to change a setting using either addArgument or set_preferences, something like this:

    options.addArguments("dom.webdriver.enabled=False");
    options.addArguments("useAutomationExtension=False");
    
    profile.setPreference("dom.webdriver.enabled", False);
    profile.setPreference("useAutomationExtension", False);        

Looking at the Javadoc isn't very helful:

addArguments Javadoc

setPreference Javadoc

Could someone explain the relation between these? Any conceptual differences? They seem very overlapping.

Furthermore, there is desiredCapabilities and capabilities that also seems very similar. Why do these exist and how do they relate to each other?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

2 Answers2

2

https://www.chromium.org/administrators/configuring-other-preferences

preferences are settings that are used to control the browser behavior , full list of supported preferences could be found at :

https://chromium.googlesource.com/chromium/src/+/7e762c1f17514a29834506860961ba2f24e7e6e5/components/content_settings/core/common/pref_names.cc

https://chromium.googlesource.com/chromium/src/+/master/chrome/common/pref_names.cc

Arguments are commands that can be passed as command line arguments to the chrome binary eg

chrome.exe --headless

https://www.selenium.dev/selenium/docs/api/java/org/openqa/selenium/chromium/ChromiumOptions.html#addArguments(java.lang.String...)

full list: https://peter.sh/experiments/chromium-command-line-switches/

For Firefox:

Arguments : https://developer.mozilla.org/en-US/docs/Mozilla/Command_Line_Options

Add all settings within the Firefox config (which you can access by typing about:config in the address bar) can be set using options.addPreference

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
PDHide
  • 18,113
  • 2
  • 31
  • 46
0

addArguments()

addArguments() is the method to configure the AbstractDriverOptions to manage the firefox specific settings in a way that geckodriver can understand using an instance of FirefoxOptions Class.

As an example:

FirefoxOptions option=new FirefoxOptions();
options.addArguments("start-maximized");

setPreference()

setPreference() is the method to configure the firefox profile specific settings in a way that geckodriver can understand using an instance of FirefoxProfile Class.

As an example:

FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.dir", "/home/ranjith/Downloads");
profile.setPreference("browser.download.folderList", 2);

References

You can find a couple of relevant detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352