简体   繁体   中英

How to solve 'Getting Default Adapter failed' error when launching Chrome and try to access a webpage using the ChromeDriver using Selenium

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.

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, ie 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/")

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.

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

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 ie outside the class level, since setUpClass() method is not executed when running from inside of the class.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM