21

I have updated Selenium but the error keeps occurring even though the web page loads. However, in some instances, the driver starts but it is stagnant. Is this causing an issue and if so, how do I resolve it?

[11556:9032:0502/152954.314:ERROR:device_event_log_impl.cc(162)] [15:29:54.314] Bluetooth: bluetooth_adapter_winrt.cc:1055 Getting Default Adapter failed.
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Bakar
  • 343
  • 1
  • 2
  • 8
  • Paste your code that you are running. Provide more description like Chrome browser, ChromeDriver , Selenium version that you are using. Also go through [How to ask question](https://stackoverflow.com/help/how-to-ask) – Alok May 02 '20 at 18:06
  • 1
    I'm getting the same error in C#. I imagine it's because there are no Bluetooth adapters on the computer running the code, but I don't see any way to disable the check. – Jake May 19 '20 at 14:33
  • 2
    Regarding @Alok's correction, there's actually enough information here, if you can believe it. For C# at least, extremely generic "open a ChromeDriver window" code (http://executeautomation.com/blog/simple-code-with-selenium-c/) will generate the error in the console. As for "more description", the versioning is the up-to-date versions of everything - ChromeDriver 81.0.4044.13800, Selenium WebDriver 3.141.0 – Jake May 19 '20 at 14:33
  • I get this error on my PC while running some Selenium tests in Python / Django / Chrome. My PC has no Bluetooth. The error message is an irritant, but doesn't actually prevent the tests from proceeding normally. I have learned to ignore it. – Dr Phil Jul 29 '22 at 19:50

4 Answers4

28

This error message...

ERROR:device_event_log_impl.cc(162)] [15:29:54.314] Bluetooth: bluetooth_adapter_winrt.cc:1055 Getting Default Adapter failed.

...implies that ScopedClosureRunner on_init failed in BluetoothAdapterWinrt::OnGetDefaultAdapter().


Analysis

This error is defined in bluetooth_adapter_winrt.cc as follows:

void BluetoothAdapterWinrt::OnGetDefaultAdapter(
    base::ScopedClosureRunner on_init,
    ComPtr<IBluetoothAdapter> adapter) {
  DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
  if (!adapter) {
    BLUETOOTH_LOG(ERROR) << "Getting Default Adapter failed.";
    return;
  }

Solution

Ensure that:

  • Selenium is upgraded to current levels Version 3.141.59.
  • ChromeDriver is updated to current ChromeDriver v84.0 level.
  • Chrome is updated to current Chrome Version 84.0 level. (as per ChromeDriver v84.0 release notes)
  • If your base Web Client version is too old, then uninstall it and install a recent GA and released version of Web Client.

Additional considerations

However it was observed that this error can be supressed by running Chrome as root user (administrator) on Linux. but that would be a deviation from the documentation in ChromeDriver - WebDriver for Chrome where it is mentioned:

A common cause for Chrome to crash during startup is running Chrome as root user (administrator) on Linux. While it is possible to work around this issue by passing '--no-sandbox' flag when creating your WebDriver session, i.e. the ChromeDriver session as such a configuration is unsupported and highly discouraged.

Ideally, you need to configure your environment to run Chrome as a regular user instead.


Suppressing the error

Finally, as per the documentation in Selenium Chrome Driver: Resolve Error Messages Regarding Registry Keys and Experimental Options these error logs can be supressed by adding the argument:

excludeSwitches: ['enable-logging']

So your effective code block will be:

from selenium import webdriver

options = webdriver.ChromeOptions() 
options.add_experimental_option("excludeSwitches", ["enable-logging"])
driver = webdriver.Chrome(options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get("https://www.google.com/")
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
2

I had simmilar problems

ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host and

Bluetooth: bluetooth_adapter_winrt.cc:1055 Getting Default Adapter failed.

Both of them disapeared after running cmd as an administrator. I don't know what is the exact cause of this issue but for me it seems that's a lack of privs while running selenium.

If anyone could explain why it is happening would be great.

Piotr
  • 161
  • 1
  • 1
  • 13
  • 1
    Piotr, I'm curious - does the computer you're running this on actually have a Bluetooth device? I'm wondering if you have such a device, maybe running cmd as an administrator gives it access to that device, so there's no error. Purely speculation, though. – Jake Aug 05 '20 at 13:38
0

Simply switching on my device's Bluetooth solved the problem... Don't know the reason behind it

  • 2
    I use Docker containers to run my code - I imagine I could add a fake Bluetooth device to them, but it seems a bit excessive! – Jake Aug 23 '20 at 01:35
-2

I was getting the same error. On a code that was working yesterday. The Code is available at this url at this moment https://youtu.be/0kLoVGLTISg?list=PLUDwpEzHYYLvx6SuogA7Zhb_hZl3sln66&t=4073

https://github.com/Microsoft/vscode-python/issues/3252 Found the Resolution hint over here in the comments section, along with https://docs.python.org/3/library/unittest.html#unittest.TestCase.setUp,

suggesting that, we cannot run on "Pycharm"/VSCode using right click -> run from within the class level, we need to run it from the module level i.e. outside the class level, since setUpClass() method is not executed when running from inside of the class.