简体   繁体   English

如何阻止 selenium 在 python 中打印 webdriver-manager 消息?

[英]How to stop selenium from printing webdriver-manager messages in python?

Each time that I initiate a new webdriver the following text is written to the console:每次我启动一个新的 webdriver 时,都会将以下文本写入控制台:

[WDM] - ====== WebDriver manager ======
[WDM] - Current google-chrome version is 102.0.5005
[WDM] - Get LATEST chromedriver version for 102.0.5005 google-chrome
[WDM] - Driver [C:\Users\klaas\.wdm\drivers\chromedriver\win32\102.0.5005.61\chromedriver.exe] found in cache

My goal was to stop selenium from printing this message to the console.我的目标是阻止 selenium 将此消息打印到控制台。 Stack Overflow threads with similar topics to this one showed two options that did not work for me.与此主题相似的 Stack Overflow 线程显示了两个对我不起作用的选项。 The first one is:第一个是:

from selenium.webdriver.chrome.options import Options

options = Options()
options.add_experimental_option("excludeSwitches", ["enable-logging"])
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)

and the second one is:第二个是:

import logging
from selenium.webdriver.remote.remote_connection import LOGGER

LOGGER.setLevel(logging.WARNING)

Both of these solutions did work for some others but not for me.这两种解决方案都适用于其他一些解决方案,但不适用于我。 Is there some other way to stop selenium from printing webdriver messages?有没有其他方法可以阻止硒打印 webdriver 消息?

Solution: As suggested by MohitC the following code prevented the webdriver-manager messages to be printed:解决方案:根据MohitC的建议,以下代码阻止打印 webdriver-manager 消息:

import logging
logging.getLogger('WDM').setLevel(logging.NOTSET)

These are webdriver-manager logs.这些是webdriver-manager日志。 You can either uninstall it if you are not using or disable logging as below如果您不使用或禁用日志记录,您可以卸载它,如下所示

import os
os.environ['WDM_LOG'] = "false"

You can also try你也可以试试

import logging
logging.getLogger('WDM').setLevel(logging.NOTSET)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何阻止 selenium 打印 WebDriver 管理器启动日志? - How to stop selenium from printing WebDriver manager startup logs? 无法运行 selenium pytest 测试与 webdriver-manager 使用 docker 容器与 Z23EEEB37947BDD25BDDZ6: - Unable to run the selenium pytest tests with webdriver-manager using the docker container with python:3.9-alpine image Selenium 只打开谷歌浏览器(使用 webdriver-manager) - Selenium opens only Google Chrome (using webdriver-manager) Selenium 启动时通过webdriver-manager安装的webdriver版本问题 - Selenium problem with the webdriver version installed through webdriver-manager while getting started 从打印/输出管理器和版本信息中停止 Selenium ChromeWebdriver? - Stop Selenium ChromeWebdriver from Printing/Outputting Manager and Version Info? 将 webdriver-manager 与 pyinstaller 一起使用时出错 - Error using webdriver-manager with pyinstaller 如何使用Selenium WebDriver + python获取浏览器控制台错误消息 - How to get browser console error messages using Selenium WebDriver + python Selenium WebDriver Python:如何在发送字符串后阻止'send_keys'命中return - Selenium WebDriver Python: How to stop 'send_keys' from hitting return after sending a string 使用 Webdriver Manager for Python 的 Selenium ChromeDriver 问题 - Selenium ChromeDriver issue using Webdriver Manager for Python Selenium的Python Webdriver - Python webdriver from Selenium
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM