How to get rid of response messages initiating Google Chrome using ChromeDriver in Python Selenium

Viewed 3338

I have problem with this that I want to have a clean terminal/output but when I use selenium in python and when I call : driver = webdriver.Chrome()

I get this message between my output :

[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.

My code doesn't have any errors but I get this temp output How can I remove this output? any code I need to remove this?

3 Answers

If you are using Selenium with Python then add these extra options into your Selenium code which will disable all the errors getting displayed on Console-

options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-logging'])
driver = webdriver.Chrome(options=options)

you can use playwright:

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

This is the Docs of playwright

These error messages...

[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.

...are the reasult of some Parametrized tests are flaky due to a timeout in recording expensive metrics on startup.


As per the discussion 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 are flaky:

Seems asvitkine@chromium.org have submitted a commit mentioning:

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.

This fix should address the issue in the upcoming releases once the flaky tests are addressed.


Temporary Solution

If you want to suppress the error logs you can add the experimental option 'excludeSwitches', ['enable-logging'] through an instance of ChromeOptions() as follows:

  • Python solution:

    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    
    options = Options()
    options.add_experimental_option('excludeSwitches', ['enable-logging'])
    
  • Java solution:

    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOptions("excludeSwitches", ['enable-logging']);
    
Related