如何在 Python Selenium 中使用 ChromeDriver 消除启动 Google Chrome 的响应消息

Moh*_*ani 5 selenium google-chrome python-3.x selenium-chromedriver selenium-webdriver

我有一个问题,我想要一个干净的终端/输出,但是当我在 python 中使用 selenium 以及当我调用时: driver = webdriver.Chrome()

我在输出之间收到此消息:

[14096:8964:1002/201524.623:ERROR:chrome_browser_main_extra_parts_metrics.cc(228)] crbug.com/1216328: Checking Bluetooth availability started. Please report if there is no report that this ends.
[14096:8964:1002/201524.623:ERROR:chrome_browser_main_extra_parts_metrics.cc(231)] crbug.com/1216328: Checking Bluetooth availability ended. 
[14096:8964:1002/201524.632:ERROR:chrome_browser_main_extra_parts_metrics.cc(234)] crbug.com/1216328: Checking default browser status started. Please report if there is no report that this ends.
[14096:5428:1002/201524.633:ERROR:device_event_log_impl.cc(214)] [20:15:24.633] Bluetooth: bluetooth_adapter_winrt.cc:1073 Getting Default Adapter failed.
[14096:8964:1002/201524.660:ERROR:chrome_browser_main_extra_parts_metrics.cc(238)] crbug.com/1216328: Checking default browser status ended.
Run Code Online (Sandbox Code Playgroud)

我的代码没有任何错误,但我得到此临时输出 如何删除此输出?我需要删除这个代码吗?

Deb*_*anB 1

这些错误信息...

[5124:4344:1128/184821.088:ERROR:chrome_browser_main_extra_parts_metrics.cc(226)] crbug.com/1216328: Checking Bluetooth availability started. Please report if there is no report that this ends.
[5124:4344:1128/184821.145:ERROR:chrome_browser_main_extra_parts_metrics.cc(229)] crbug.com/1216328: Checking Bluetooth availability ended.
Run Code Online (Sandbox Code Playgroud)

...是由于启动时记录昂贵指标超时而导致某些参数化测试不稳定的结果。


根据讨论参数化测试因启动时记录昂贵指标超时而不稳定, isherman@chromium.org提到chrome_browser_main_extra_parts_metrics.cc中的任一调用都不稳定:

似乎asvitkine@chromium.org已经提交了一份提交,其中提到:

不要在 Linux 上记录直方图 DefaultBrowser.State。查询默认浏览器状态的代码有时会挂起 Chrome 在浏览器测试机器人上的启动,从而导致不稳定。在Linux上禁用相关代码,直到找到解决方案。此外,修改一些检测消息,使其更简洁、更清楚地说明相关错误何时可能发生。一旦这个问题落地,我们应该能够看到是否有更多的测试受此影响,或者是否可以关闭错误并删除诊断日志。

一旦解决了不稳定的测试,此修复应该可以解决即将发布的版本中的问题。


临时解决方案

如果您想抑制错误日志,您可以'excludeSwitches', ['enable-logging']通过以下实例添加实验选项ChromeOptions()

  • Python解决方案:

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    
    options = Options()
    options.add_experimental_option('excludeSwitches', ['enable-logging'])
    
    Run Code Online (Sandbox Code Playgroud)
  • Java解决方案:

    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOptions("excludeSwitches", ['enable-logging']);
    
    Run Code Online (Sandbox Code Playgroud)