Passing options to chrome driver selenium

21,075

Solution 1

Hinted by this Chromedriver ticket (about the silent option), I looked in the source of ChromeDriverService.java, and found a reference to "webdriver.chrome.logfile".

After adding -Dwebdriver.chrome.logfile="/dev/null" to my java command, the logs became readable again: The usless ChromeDriver logs were gone, while theSystem.out.println calls and exceptions are still shown in the console.

I start java with the following parameters (Linux / Mac):

DIR=path/to/dir/containing/selenium/and/stuff
cd "$DIR" && java -cp "$DIR\
:$DIR/output\
:$DIR/bin/selenium-server-standalone-2.33.0.jar" \
-Dwebdriver.chrome.driver="$DIR/bin/chromedriver" \
-Dwebdriver.chrome.args="--disable-logging" \
-Dwebdriver.chrome.logfile="/dev/null" \
AllTests

If you're on Windows:

set DIR=path\to\dir\containing\selenium\and\stuff
cd "%DIR%" && java -cp "%DIR%;%DIR%\output;%DIR%\bin\selenium-server-standalone-2.33.0.jar" ^
-Dwebdriver.chrome.driver="%DIR%\bin\chromedriver.exe" ^
-Dwebdriver.chrome.args="--disable-logging" ^
-Dwebdriver.chrome.logfile=NUL ^
AllTests

Explanation for the composition of my classpath (-cp): My tests are located in a directory at "$DIR/output". The Selenium jar file is placed in "$DIR/bin/selenium-server-standalone-2.33.0.jar". "AllTests" is the name of my class containing public static void main(String[] args) - this launches my tests.

The other parameters are self-explanatory, adjust it to your needs. For convenience (used in a shell/batch script), I've declared the common directory in a variable DIR.

Solution 2

When I was setting chrome up with

  selenium-chrome-driver-2.48.2.jar
  chromedriver 2.20
  selenium-java-2.48.2.jar

none of the above answers worked for me, Since I see some of the answers are a few years old, I will post what worked for me.

    ChromeOptions chromeOptions = setupChromeOptions();
    System.setProperty("webdriver.chrome.logfile", "\\path\\chromedriver.log");
    System.setProperty("webdriver.chrome.driver", "\\path\\chromedriver.exe");
    System.setProperty("webdriver.chrome.args", "--disable-logging");
    System.setProperty("webdriver.chrome.silentOutput", "true");
    driver = new ChromeDriver(chromeOptions);

Solution 3

Try "--disable-logging" instead.

DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--disable-logging"));
chrome = new ChromeDriver(_chromeservice,capabilities);
Share:
21,075
Lazadon
Author by

Lazadon

I enjoy Learning New Languages and finding creative ways to use them.

Updated on July 31, 2022

Comments

  • Lazadon
    Lazadon almost 2 years

    I am trying to disable the output to the console for chrome. If I pass the --start-maximized option it works fine. I may have the wrong command?

    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setCapability("chrome.switches", Arrays.asList("--silent"));
    chrome = new ChromeDriver(_chromeservice,capabilities);
    

    I also tried

     ChromeOptions options = new ChromeOptions();
     options.addArguments("silent");
     chrome = new ChromeDriver(options);
    

    Output

    Started ChromeDriver port=26703 version=23.0.1240.0 log=/Brett/workspace/TestNG/chromedriver.log [1214/161331:ERROR:ipc_sync_channel.cc(378)] Canceling pending sends [1214/161331:ERROR:ipc_sync_channel.cc(378)] Canceling pending sends [1214/161331:ERROR:ipc_sync_channel.cc(378)] Canceling pending sendsBlockquote

  • Lazadon
    Lazadon over 11 years
    Thanks for your reply. I tried it and it's still outputting the same information.
  • Ashwin Prabhu
    Ashwin Prabhu over 11 years
    BTW what you see are not really errors per say, since they are not affecting chrome driver execution in any way, right?
  • Lazadon
    Lazadon over 11 years
    No it does not effect the execution of any tests. I am just thinking down the line. After a while it will take up a lot of space in the log file.
  • user2087450
    user2087450 almost 11 years
    Could you clearly explain how to use it in Java and Windows. I mean please add your code
  • Rob W
    Rob W almost 11 years
    @user2087450 See revised answer.
  • Sridhar Sarnobat
    Sridhar Sarnobat over 7 years
    Bingo. I needed logfile, args AND silentOutput. The output looks so much nicer now. Proof that small things make a big difference.