如何在 Python Selenium 中使用 ChromeDriver 摆脱启动 Google Chrome 的响应消息
How to get rid of response messages initiating Google Chrome using ChromeDriver in Python Selenium
我对此有疑问,我想要一个干净的 terminal/output 但是当我在 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.
我的代码没有任何错误,但我得到了这个临时输出
我怎样才能删除这个输出?我需要删除这个的任何代码吗?
你可以使用编剧:
pip install --upgrade pip
pip install playwright
playwright install
import asyncio
from playwright.async_api import async_playwright
async def main():
async with async_playwright() as p:
browser = await p.chromium.launch()
page = await browser.new_page()
await page.goto("http://playwright.dev")
print(await page.title())
await browser.close()
asyncio.run(main())
这是剧作家Docs的
如果您将 Selenium 与 Python 一起使用,则将这些额外选项添加到您的 Selenium 代码中,这将禁用控制台上显示的所有错误-
options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-logging'])
driver = webdriver.Chrome(options=options)
这些错误信息...
[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.
...是一些 参数化测试不稳定的结果,因为在启动时记录昂贵的指标超时。
根据讨论 Parametrized tests are flaky due to a timeout in recording expensive metrics on startup isherman@chromium.org
mentions either of the calls in chrome_browser_main_extra_parts_metrics.cc 是不稳定的:
似乎 asvitkine@chromium.org
提交了 commit 提及:
Don't log histogram DefaultBrowser.State on Linux. The code to query
the default browser state sometimes hangs Chrome start up on browser
tests bots, causing flakiness. Disable the relevant code on Linux
until a solution can be found. Also, revise some instrumentation
messages to be more concise and more clear about when the bug in
question might happen. Once this lands, we should be able to see if
any more tests are affected by this or whether the bug can be closed
and diagnostic logs can be removed.
一旦 易碎测试 得到解决,此修复程序应该会解决即将发布的版本中的问题。
临时解决方案
如果您想抑制错误日志,您可以通过 ChromeOptions()
的实例添加实验性选项 'excludeSwitches', ['enable-logging']
,如下所示:
Python解法:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_experimental_option('excludeSwitches', ['enable-logging'])
Java解法:
ChromeOptions options = new ChromeOptions();
options.setExperimentalOptions("excludeSwitches", ['enable-logging']);
我对此有疑问,我想要一个干净的 terminal/output 但是当我在 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.
我的代码没有任何错误,但我得到了这个临时输出 我怎样才能删除这个输出?我需要删除这个的任何代码吗?
你可以使用编剧:
pip install --upgrade pip
pip install playwright
playwright install
import asyncio
from playwright.async_api import async_playwright
async def main():
async with async_playwright() as p:
browser = await p.chromium.launch()
page = await browser.new_page()
await page.goto("http://playwright.dev")
print(await page.title())
await browser.close()
asyncio.run(main())
这是剧作家Docs的
如果您将 Selenium 与 Python 一起使用,则将这些额外选项添加到您的 Selenium 代码中,这将禁用控制台上显示的所有错误-
options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-logging'])
driver = webdriver.Chrome(options=options)
这些错误信息...
[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.
...是一些 参数化测试不稳定的结果,因为在启动时记录昂贵的指标超时。
根据讨论 Parametrized tests are flaky due to a timeout in recording expensive metrics on startup isherman@chromium.org
mentions either of the calls in chrome_browser_main_extra_parts_metrics.cc 是不稳定的:
似乎 asvitkine@chromium.org
提交了 commit 提及:
Don't log histogram DefaultBrowser.State on Linux. The code to query the default browser state sometimes hangs Chrome start up on browser tests bots, causing flakiness. Disable the relevant code on Linux until a solution can be found. Also, revise some instrumentation messages to be more concise and more clear about when the bug in question might happen. Once this lands, we should be able to see if any more tests are affected by this or whether the bug can be closed and diagnostic logs can be removed.
一旦 易碎测试 得到解决,此修复程序应该会解决即将发布的版本中的问题。
临时解决方案
如果您想抑制错误日志,您可以通过 ChromeOptions()
的实例添加实验性选项 'excludeSwitches', ['enable-logging']
,如下所示:
Python解法:
from selenium import webdriver from selenium.webdriver.chrome.options import Options options = Options() options.add_experimental_option('excludeSwitches', ['enable-logging'])
Java解法:
ChromeOptions options = new ChromeOptions(); options.setExperimentalOptions("excludeSwitches", ['enable-logging']);