38

I am running python script (complete script link below) for selenium test using Chrome Canary. The test seems to be running fine, however, there are lots of error/warning/info messages displayed on the console.

Is there a way to suppress these messages? I have tried: chrome_options.add_argument("--silent"), but does not help. I am not able to find the right solution. Appreciate any help.

Python script : Example script provided here

Python: 3.6.3 Selenium: 3.6.0 Chrome Canary: 63.0.3239.5 (64 bit) ChromeDriver : 2.33

Console messages

Tarun Lalwani
  • 133,941
  • 8
  • 173
  • 238
Gagan Shrestha
  • 393
  • 1
  • 4
  • 10
  • For me it doesn't happen. It may be because you are using canary build. Try using `chrome_options.add_argument("--disable-logging")` – Tarun Lalwani Oct 14 '17 at 14:29
  • Tried that argument but still the same. And I agree it is because of canary build as normal chrome build works fine, however, I am trying selenium with headless chrome. Thanks for reply @TarunLalwani. – Gagan Shrestha Oct 15 '17 at 00:04

6 Answers6

54

Try options.add_argument('log-level=3').

log-level: 
Sets the minimum log level.
Valid values are from 0 to 3: 

    INFO = 0, 
    WARNING = 1, 
    LOG_ERROR = 2, 
    LOG_FATAL = 3.

default is 0.
ggorlen
  • 33,459
  • 6
  • 59
  • 67
nosam
  • 621
  • 4
  • 4
  • Had the same kind of issue with Node.js using Protractor and headless chrome (version 65 on win64). Setting log-level=2 fixed the problem for me. – ChrisB Jan 26 '18 at 15:09
  • This approach evidently reduced the logs. However, there's still some logs printed, although they didn't influence the workflow. One of the logs: `[0817/100109.981:ERROR:socket_manager.cc(128)] Failed to resolve address for stun.services.mozilla.com., errorcode: -105` – PRO Aug 17 '21 at 02:01
10

If "--log-level" doesn't work for you (as of 75.0.3770.100 it didn't for me), this should:

options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-logging'])
driver = webdriver.Chrome(executable_path='<path-to-chrome>', options=options)

see:

https://bugs.chromium.org/p/chromedriver/issues/detail?id=2907#c3

Python selenium: DevTools listening on ws://127.0.0.1

gss
  • 595
  • 7
  • 9
9

Works for me in Python/Chrome...

from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--log-level=3')
kohane15
  • 643
  • 11
  • 14
7

You can take help of below link.

List of Chromium Command Line Switches

"--log-level" sets the minimum log level. Valid values are from 0 to 3: INFO = 0, WARNING = 1, LOG_ERROR = 2, LOG_FATAL = 3.

Shashank
  • 621
  • 7
  • 16
3

I have just tested this one, it works for me (C#):

    ChromeOptions options = new ChromeOptions();
    options.AddArguments("--headless", "--log-level=3");
    RemoteWebDriver driver = new ChromeDriver(options);
ondrax
  • 31
  • 1
0
import os
os.environ['WDM_LOG_LEVEL'] = '0'

That code hides the console output for from webdriver_manager.chrome import ChromeDriverManager console outputs

Chris P
  • 1,819
  • 2
  • 28
  • 49