43

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
  • 142,312
  • 9
  • 204
  • 265
Gagan Shrestha
  • 443
  • 1
  • 5
  • 10
  • 1
    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

7 Answers7

68

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
  • 44,755
  • 7
  • 76
  • 106
nosam
  • 761
  • 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
14

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)
General Grievance
  • 4,555
  • 31
  • 31
  • 45
gss
  • 653
  • 8
  • 9
14

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
  • 809
  • 12
  • 16
8

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
  • 709
  • 8
  • 16
5

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
  • 51
  • 1
  • 1
1
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
  • 2,059
  • 4
  • 34
  • 68
0

The FULL answer is you need to turn the logging off using:-

options = Options()
options.add_argument('--headless')
options.add_argument('log-level=3')
driver = webdriver.Chrome(options=options)  # or webdriver.Chrome(), etc.

but you cannot get rid of the console log output of:-

DevTools listening on ws://127.0.0.1:#####/devtools/browser*****

You'll just stop the logging of the selenium messages into the terminal/console.