【问题标题】:How to stop selenium from printing WebDriver manager startup logs?如何阻止硒打印 WebDriver 管理器启动日志?
【发布时间】:2022-01-13 14:44:36
【问题描述】:

当我启动一个新的 selenium 驱动程序时,我收到一条消息:

====== 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

我尝试使用:

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

但没有一个有效。

有没有更好的办法?

【问题讨论】:

    标签: python python-3.x selenium logging webdrivermanager-python


    【解决方案1】:

    要静默 webdrivermanager-python 日志并将它们从控制台中删除,您可以使用 0 初始化环境变量 WDM_LOG_LEVEL 硒测试前的值如下:

    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")
    

    【讨论】:

      【解决方案2】:

      您使用的是网络驱动程序管理器吗?看起来这就是给你日志的原因 (pip install webdriver-manager) 。我在没有网络驱动程序管理器的情况下使用 selenium 或添加任何 chrome 选项来删除日志,并且没有打印任何日志。

      另见:Turning off logging in Selenium (from Python)

      【讨论】:

        【解决方案3】:

        您为chrome_options 设置的log-level 与您使用Python 的外部库webdrivermanager 看到的日志完全不同。该库将有自己的方式来禁用日志消息(或者至少应该如此)。还有其他用于管理 WebDriver 安装的 Python 库,例如 SeleniumBase。相关的,您或许可以更改 Python 日志记录级别以隐藏该消息,有关详细信息,请参阅 Dynamically changing log level without restarting the application

        【讨论】:

          猜你喜欢
          • 2020-03-27
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-03-05
          • 2019-06-14
          • 2013-07-23
          相关资源
          最近更新 更多