Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable logging using Selenium with Python binding

Simple question: how to completely disable logging when using Selenium from Python bindings, ex code as follows:

browser = webdriver.Chrome()

I've tried things like:

options = webdriver.ChromeOptions();
options.add_argument('--log-level 3') 
browser = webdriver.Chrome(chrome_options=options)

or even:

options = webdriver.ChromeOptions();
options.add_argument('--disable-logging') 
browser = webdriver.Chrome(chrome_options=options)

but still the file 'chromedriver.log' is appearing on each new run of the tests.

like image 367
Rabih Kodeih Avatar asked Jul 23 '12 13:07

Rabih Kodeih


2 Answers

The source code of Chrome's webdriver, shows the existence of an option called service_log_path.

So if you want to get rid of the file, you could set this property to

  • /dev/null if you are running under Linux/Unix ;
  • NUL under windows

Hope it helps

like image 185
Y__ Avatar answered Oct 17 '22 03:10

Y__


You may set options.add_argument("--log-level=3") for Chrome browser to be run with Selenuim, or you may set logging level to some higher level with:

import logging
logger = logging.getLogger('selenium.webdriver.remote.remote_connection')
logger.setLevel(logging.WARNING)  # or any variant from ERROR, CRITICAL or NOTSET

But some messages will appear anyway in this case, including the starting DevTools message or SSL handshake error messages.

To run Chrome browser with Selenium in console in completely silent mode, you should use this snippet:

options = Options()
options.headless = True
options.add_experimental_option("excludeSwitches", ["enable-logging"])

That trick will suppress any console message from either the Selenium driver or the browser itself, including the first message DevTools listening on ws://127.0.0.1 at the very start.

At the same time some runtime step-by-step data can be saved to service log file, in case its argument has been added.

like image 29
architux Avatar answered Oct 17 '22 04:10

architux