How to disable logging using Selenium with Python

2019-01-28 02:06发布

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.

3条回答
趁早两清
2楼-- · 2019-01-28 02:38

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

查看更多
地球回转人心会变
3楼-- · 2019-01-28 02:38
driver = webdriver.Chrome(service_log_path='/dev/null')
查看更多
在下西门庆
4楼-- · 2019-01-28 02:41

Just example for Windows people:

webdriver.Firefox(log_path='NUL')

Accepted answer is correct, but if you are new to Python / windows like i am, example like this will cut you few hours of google time.

查看更多
登录 后发表回答