我已经更新了 Selenium,但即使网页加载,错误仍然会发生。然而,在某些情况下,驱动程序启动但它是停滞的。这是否会导致问题,如果是,我该如何解决?
[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.
最佳答案
此错误消息...
ERROR:device_event_log_impl.cc(162)] [15:29:54.314] Bluetooth: bluetooth_adapter_winrt.cc:1055 Getting Default Adapter failed.
...暗示 ScopedClosureRunner on_init
失败 BluetoothAdapterWinrt::OnGetDefaultAdapter()
.分析
此错误在 bluetooth_adapter_winrt.cc 中定义如下:
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;
}
解决方案
确保这件事:
其他注意事项
但是,可以通过将 Chrome 运行为 来抑制此错误。
root
Linux 上的用户 ( administrator
)。但这与 ChromeDriver - WebDriver for Chrome 中的文档有所不同。提到它的地方: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.
理想情况下,您需要将环境配置为以普通用户身份运行 Chrome。
抑制错误
最后,根据 Selenium Chrome Driver: Resolve Error Messages Regarding Registry Keys and Experimental Options 中的文档这些错误日志可以通过添加参数来抑制:
excludeSwitches: ['enable-logging']
因此,您的有效代码块将是: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/")
关于python - 如何解决启动 Chrome 时出现 'Getting Default Adapter failed' 错误并尝试使用 Selenium 使用 ChromeDriver 访问网页,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61561112/