Ezriel_S
Ezriel_S

Reputation: 218

How to stop selenium from printing WebDriver manager startup logs?

When I'm launching a new selenium driver I get a message as:

====== WebDriver manager ======
Current chromium version is 90.0.4430
Get LATEST chromedriver version for 90.0.4430 chromium
Driver [/root/.wdm/drivers/chromedriver/linux64/90.0.4430.24/chromedriver] found in cache

I tryed using:

chrome_options.add_experimental_option("excludeSwitches", ["enable-logging"])
chrome_options.add_argument('log-level=2')

But none worked.

Is there a better way ?

Upvotes: 0

Views: 6026

Answers (6)

pritam shasanee
pritam shasanee

Reputation: 11

The solution is setting the log level of selenium and the logging of the OS.

For windows:

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

which will only tell you the warnings and errors related to selenium. And:

logging.disable(logging.CRITICAL)

will suppress all the logs by Windows. Here's how you can do it:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import logging

logging.disable(logging.CRITICAL)

options = Options()
options.add_argument('--log-level=3')
driver = webdriver.Chrome(options=options)
driver.get("https://www.google.com")

Upvotes: 0

Piyush Kakkar
Piyush Kakkar

Reputation: 79

This worked for me for webdriver_manager v3.8.3:

from webdriver_manager.core.logger import __logger as wdm_logger
wdm_logger.setLevel(logging.WARNING)

Upvotes: 0

yaqin2015
yaqin2015

Reputation: 66

according to documents: just add below code into your files:

import os
os.environ['WDM_LOG'] = '0'

i have tried it with myself, working very well

Upvotes: 4

undetected Selenium
undetected Selenium

Reputation: 193058

To silent webdrivermanager-python logs and remove them from console, you can initialize the env variable WDM_LOG_LEVEL with 0 value before your selenium tests as follows:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
import os

os.environ['WDM_LOG_LEVEL'] = '0'
options = Options()
options.add_argument("start-maximized")
options.add_experimental_option('excludeSwitches', ['enable-logging'])
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
driver.get("https://www.google.com")

Upvotes: 2

Michael Mintz
Michael Mintz

Reputation: 15426

The log-level that you are setting for chrome_options is completely separate from the logs that you are seeing from using the external library webdrivermanager for Python. That library will have its own way of disabling log messages (or at least it should). There are other Python libraries for managing WebDriver installs, such as SeleniumBase for example. Related, you might be able to change the Python logging level to hide that message, see Dynamically changing log level without restarting the application for details.

Upvotes: 1

01Cyber_cyber10
01Cyber_cyber10

Reputation: 11

Are you using web driver manager? it looks like that is what is giving you logs (pip install webdriver-manager) . Im using selenium without web driver manager or adding any chrome options to remove logs , and not getting any logs printed.

also see :Turning off logging in Selenium (from Python)

Upvotes: 0

Related Questions