Android的debug包,从原生切到webview报错

环境:Android10(真机),Window10,Python3, Appium v1.18.0,Chromedriver
切换webview代码

WebDriverWait(self._driver, 60).until(lambda x: len(self._driver.contexts) > 1)
 #切换到webview
 self._driver.switch_to.context(self._driver.contexts[-1])
 print(self._driver.contexts)

报错日志:
[debug] [Chromedriver] Cleaning this device’s adb forwarded port socket connections: abfb5a32
[debug] [ADB] List forwarding ports
[debug] [ADB] Running ‘C:\Program Files (x86)\Android\android-sdk\platform-tools\adb.exe -P 5037 -s abfb5a32 forward --list’
[Chromedriver] Spawning chromedriver with: C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe --url-base=wd/hub --port=8000 --adb-port=5037 --verbose
[debug] [Chromedriver] Chromedriver version: ‘88.0.4324.96’
[debug] [WD Proxy] Matched ‘/status’ to command name ‘getStatus’
[debug] [WD Proxy] Proxying [GET /status] to [GET http://127.0.0.1:8000/wd/hub/status] with no body
[debug] [WD Proxy] Got response with status 200: {“value”:{“build”:{“version”:“88.0.4324.96 (68dba2d8a0b149a1d3afac56fa74648032bcf46b-refs/branch-heads/4324@{#1784})”},“message”:“ChromeDriver ready for new sessions.”,“os”:{“arch”:“x86_64”,“name”:“Windows NT”,“version”:“10.0.17763”},“ready”:true}}
[Chromedriver] Starting W3C Chromedriver session with capabilities: {
[Chromedriver] “capabilities”: {
[Chromedriver] “alwaysMatch”: {
[Chromedriver] “goog:chromeOptions”: {
[Chromedriver] “androidPackage”: “com.fcbox.hivebox”,
[Chromedriver] “androidUseRunningApp”: true,
[Chromedriver] “androidDeviceSerial”: “abfb5a32”
[Chromedriver] },
[Chromedriver] “goog:loggingPrefs”: {
[Chromedriver] “browser”: “ALL”
[Chromedriver] }
[Chromedriver] }
[Chromedriver] }
[Chromedriver] }
[debug] [WD Proxy] Matched ‘/session’ to command name ‘createSession’
[debug] [WD Proxy] Proxying [POST /session] to [POST http://127.0.0.1:8000/wd/hub/session] with body: {“capabilities”:{“alwaysMatch”:{“goog:chromeOptions”:{“androidPackage”:“com.fcbox.hivebox”,“androidUseRunningApp”:true,“androidDeviceSerial”:“abfb5a32”},“goog:loggingPrefs”:{“browser”:“ALL”}}}}
[WD Proxy] Got response with status 500: {“value”:{“error”:“unknown error”,“message”:“unknown error: Failed to get sockets matching: @weblayer_devtools_remote_.*8571\n (make sure the app has its WebView/WebLayer configured for debugging)”,“stacktrace”:"Backtrace:\n\tGetHandleVerifier [0x001CB963+483]\n\tGetHandleVerifier [0x001CB941+449]\n\tGetHandleVerifier [0x00573308+3832712]\n\tGetHandleVerifier [0x0055D63F+3743423]\n\tGetHandleVerifier [0x00564BFA+3773562]\n\tGetHandleVerifier [0x00564634+3772084]\n\tGetHandleVerifier [0x00588560+3919328]\n\tGetHandleVerifier [0x00587D25+3917221]\n\tGetHandleVerifier [0x005AE7FE+4075646]\n\tGetHandleVerifier [0x005AE56C+4074988]\n\tGetHandleVerifier [0x005AB2EB+4062059]\n\tGetHandleVerifier [0x0058ED14+3945876]\n\tGetHandleVerifier [0x0058FBCE+3949646]\n\tGetHandleVerifier [0x0058FB59+3949529]\n\tOrdinal0 [0x0018B5CC+46540]\n\tOrdinal0 [0x00189F53+40787]\n\tOrdinal0 [0x00189B12+39698]\n\tGetHandleVerifier [0x00491468+2907368]\n\tGetHandleVerifier [0x002D71EE+1096302]\n\tGetHandleVerifier [0x00293E8D+821005]…
[debug] [W3C] Matched W3C error code ‘unknown error’ to UnknownError
[debug] [Chromedriver] UnknownError: An unknown server-side error occurred while processing the command. Original error: unknown error: Failed to get sockets matching: @weblayer_devtools_remote_.*8571
[debug] [Chromedriver] (make sure the app has its WebView/WebLayer configured for debugging)
[debug] [Chromedriver] at errorFromW3CJsonCode (d:\Users\003041\Application Data\npm\node_modules\appium\node_modules_appium-base-driver@7.1.0@appium-base-driver\lib\protocol\errors.js:780:25)

  • 看下有没有开启webview调试
  • 先打印下contexts 看看有没有检测到webview

跟你的chromedriver的版本有关,可能对应的版本太新了。webview的启动出现



检查webview基本环境的命令

adb shell dumpsys package com.android.webview | grep versionName
adb shell dumpsys package com.android.chrome | grep versionName
adb shell cat /proc/net/unix | grep webview
1 Like