How to ensure cli arguments work with Web Driver Manager on Windows?

0

I'm using selenium with the chromedriver (gotten via webdrivermanager in maven), the cli arguments I pass via ChromeOptions aren't applied when on windows.

However on MacOS it works fine, and on linux it partly works (as in it loads, but some debugs show) whilst on windows everything shows.

I've tried setting the chrome arguments, however it doesn't seem to do much.

        Logger.getLogger("org.openqa.selenium.remote").setLevel(Level.OFF);
        System.setProperty("webdriver.chrome.silentLogging", "true");
        System.setProperty("webdriver.chrome.verboseLogging", "false");
        System.setProperty("webdriver.chrome.silentOutput", "true");
        LogFactory.getFactory().setAttribute("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");

        WebDriverManager.chromedriver().setup();

        ChromeOptions options = new ChromeOptions();
        options.addArguments("start-maximized"); // open Browser in maximized mode
        options.addArguments("disable-infobars"); // disabling infobars
        options.addArguments("--disable-extensions"); // disabling extensions
        options.addArguments("--disable-gpu"); // applicable to windows os only
        options.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
        options.addArguments("--disable-logging"); // overcome limited resource problems
        options.addArguments("--no-sandbox"); // Bypass OS security model
        options.addArguments("--silent");
        options.addArguments("--headless");
        options.addArguments("--user-agent =\"" + configManager.getJsonReader().get("user-agent") + "\"");

        options.setBinary(WebDriverManager.chromedriver().getBinaryPath());

        browser = new ChromeDriver(options);
        ((ChromeDriver) browser).setLogLevel(Level.OFF);

I'm expecting to get a silenced output, but instead I get tons of logs, from log levels, to local port connections allowed and whatever else.

Following this is the error I get in my console:

Mar 30, 2019 11:31:17 AM java.util.prefs.WindowsPreferences <init>
WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5.
Invalid --log-level value.
Unable to initialize logging. Exiting...
Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Chrome failed to start: was killed
  (unknown error: DevToolsActivePort file doesn't exist)
java
selenium
selenium-chromedriver
webdrivermanager-java
asked on Stack Overflow Mar 30, 2019 by Charlie • edited Mar 30, 2019 by Charlie

1 Answer

0

This line is incorrect, you have to remove it from your code:

options.setBinary(WebDriverManager.chromedriver().getBinaryPath());

The method setBinary is for setting the path of the browser (Chrome in your case), not the driver (chromedriver in your case, automatically downloaded by WebDriverManager).

answered on Stack Overflow Mar 31, 2019 by Boni GarcĂ­a

User contributions licensed under CC BY-SA 3.0