Appium 使用 UIautomator2 时,执行遍历页面元素脚本时报错

micheal24 · 2019年12月24日 · 最后由 micheal24 回复于 2019年12月24日 · 4501 次阅读

appium 版本:1.8.1
模拟器:Genymotion

使用 UIautomator2 遍历元素时在遍历到第 2 个元素时就会报错,改成 UIautomator 脚本就正常执行,因为 app 中必须要用到 UIautomator2 所以必须要使用。一直找不到原因还请各位老师帮忙看看具体是什么原因。

执行脚本

下面是 appium 中的报错信息
(node:18584) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
[Appium] Welcome to Appium v1.8.1
[Appium] Non-default server args:
[Appium] address: 127.0.0.1
[Appium] sessionOverride: true
[Appium] Appium REST http interface listener started on 127.0.0.1:4723
[HTTP] --> POST /wd/hub/session
[HTTP] {"capabilities":{"firstMatch":[{"platformName":"Android","appium:automationName":"UIautomator2","appium:platformVersion":"9","appium:deviceName":"192.168.35.101:5555","appium:app":"F:/GsoSiAutomatedTesting/GaoSiAutomatedTesting/app/app-release.apk","appium:noReset":true,"appium:appPackage":"gaosi.com.jion","appium:appActivity":"gaosi.com.jion.studentapp.loading.SplashingActivity","appium:resetKeyboard":true,"appium:unicodeKeyboard":true,"appium:newCommandTimeout":60}]},"desiredCapabilities":{"platformName":"Android","automationName":"UIautomator2","platformVersion":"9","deviceName":"192.168.35.101:5555","app":"F:/GsoSiAutomatedTesting/GaoSiAutomatedTesting/app/app-release.apk","noReset":true,"appPackage":"gaosi.com.jion","appActivity":"gaosi.com.jion.studentapp.loading.SplashingActivity","resetKeyboard":true,"unicodeKeyboard":true,"newCommandTimeout":60}}
[debug] [MJSONWP] Calling AppiumDriver.createSession() with args: [{"platformName":"Android","automationName":"UIautomator2","platformVersion":"9","deviceName":"192.168.35.101:5555","app":"F:/GsoSiAutomatedTesting/GaoSiAutomatedTesting/app/app-release.apk","noReset":true,"appPackage":"gaosi.com.jion","appActivity":"gaosi.com.jion.studentapp.loading.SplashingActivity","resetKeyboard":true,"unicodeKeyboard":true,"newCommandTimeout":60},null,{"firstMatch":[{"platformName":"Android","appium:automationName":"UIautomator2","appium:platformVersion":"9","appium:deviceName":"192.168.35.101:5555","appium:app":"F:/GsoSiAutomatedTesting/GaoSiAutomatedTesting/app/app-release.apk","appium:noReset":true,"appium:appPackage":"gaosi.com.jion","appium:appActivity":"gaosi.com.jion.studentapp.loading.SplashingActivity","appium:resetKeyboard":true,"appium:unicodeKeyboard":true,"appium:newCommandTimeout":60}]}]
[debug] [BaseDriver] Event 'newSessionRequested' logged at 1577161425194 (12:23:45 GMT+0800 (GMT+08:00))
[Appium] Creating new AndroidUiautomator2Driver (v1.12.0) session
[Appium] Capabilities:
[Appium] platformName: Android
[Appium] automationName: UIautomator2
[Appium] platformVersion: 9
[Appium] deviceName: 192.168.35.101:5555
[Appium] app: F:/GsoSiAutomatedTesting/GaoSiAutomatedTesting/app/app-release.apk
[Appium] noReset: true
[Appium] appPackage: gaosi.com.jion
[Appium] appActivity: gaosi.com.jion.studentapp.loading.SplashingActivity
[Appium] resetKeyboard: true
[Appium] unicodeKeyboard: true
[Appium] newCommandTimeout: 60
[debug] [BaseDriver] W3C capabilities {"alwaysMatch":{"platformNa... and MJSONWP desired capabilities [object Object] were provided
[debug] [BaseDriver] Creating session with W3C capabilities: {"alwaysMatch":{"platformNa...
[BaseDriver] Session created with session id: 2c22dbfc-a330-4d5b-af88-43596692a899
[BaseDriver] Using local app 'F:/GsoSiAutomatedTesting/GaoSiAutomatedTesting/app/app-release.apk'
[debug] [UiAutomator2] Checking whether app is actually present
[debug] [AndroidDriver] Getting Java version
[AndroidDriver] Java version is: 1.8.0_101
[ADB] Checking whether adb is present
[ADB] Found 7 'build-tools' folders under 'F:\android-sdk\android-sdk' (newest first):
[ADB] F:/android-sdk/android-sdk/build-tools/28.0.3
[ADB] F:/android-sdk/android-sdk/build-tools/23.0.1
[ADB] F:/android-sdk/android-sdk/build-tools/22.0.1
[ADB] F:/android-sdk/android-sdk/build-tools/21.1.2
[ADB] F:/android-sdk/android-sdk/build-tools/20.0.0
[ADB] F:/android-sdk/android-sdk/build-tools/19.1.0
[ADB] F:/android-sdk/android-sdk/build-tools/19.0.3
[ADB] Using adb.exe from F:\android-sdk\android-sdk\platform-tools\adb.exe
[AndroidDriver] Retrieving device list
[debug] [ADB] Trying to find a connected android device
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[AndroidDriver] Looking for a device with Android '9'
[debug] [ADB] Setting device id to 192.168.35.101:5555
[ADB] Getting device platform version
[debug] [ADB] Running 'F:\android-sdk\android-sdk\platform-tools\adb.exe -P 5037 -s 192.168.35.101:5555 shell getprop ro.build.version.release'
[debug] [ADB] Current device property 'ro.build.version.release': 9
[AndroidDriver] Using device: 192.168.35.101:5555
[debug] [ADB] Setting device id to 192.168.35.101:5555
[debug] [ADB] Running 'F:\android-sdk\android-sdk\platform-tools\adb.exe -P 5037 -s 192.168.35.101:5555 shell getprop ro.build.version.sdk'
[debug] [ADB] Current device property 'ro.build.version.sdk': 28
[debug] [ADB] Device API level: 28
[ADB] Getting device platform version
[debug] [ADB] Running 'F:\android-sdk\android-sdk\platform-tools\adb.exe -P 5037 -s 192.168.35.101:5555 shell getprop ro.build.version.release'
[debug] [ADB] Current device property 'ro.build.version.release': 9
[debug] [ADB] Running 'F:\android-sdk\android-sdk\platform-tools\adb.exe -P 5037 -s 192.168.35.101:5555 shell wm size'
[debug] [ADB] Running 'F:\android-sdk\android-sdk\platform-tools\adb.exe -P 5037 -s 192.168.35.101:5555 shell wm density'
[debug] [ADB] Running 'F:\android-sdk\android-sdk\platform-tools\adb.exe -P 5037 -s 192.168.35.101:5555 shell getprop ro.product.model'
[debug] [ADB] Current device property 'ro.product.model': Google Pixel
[debug] [ADB] Running 'F:\android-sdk\android-sdk\platform-tools\adb.exe -P 5037 -s 192.168.35.101:5555 shell getprop ro.product.manufacturer'
[debug] [ADB] Current device property 'ro.product.manufacturer':
[debug] [ADB] Device API level: 28
[debug] [ADB] Running 'F:\android-sdk\android-sdk\platform-tools\adb.exe -P 5037 -s 192.168.35.101:5555 shell am force-stop io.appium.uiautomator2.server'
[debug] [ADB] Checking app cert for E:\FRONT\nodejs\node_gobal\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-v1.12.0.apk
[ADB] Using apksigner.bat from F:\android-sdk\android-sdk\build-tools\28.0.3\apksigner.bat
[debug] [ADB] Starting 'F:\android-sdk\android-sdk\build-tools\28.0.3\apksigner.bat' with args 'verify,--print-certs,E:\FRONT\nodejs\node_gobal\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-v1.12.0.apk'
[debug] [ADB] 'E:\FRONT\nodejs\node_gobal\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-v1.12.0.apk' is already signed.
[debug] [ADB] Checking app cert for E:\FRONT\nodejs\node_gobal\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-debug-androidTest.apk
[debug] [ADB] Starting 'F:\android-sdk\android-sdk\build-tools\28.0.3\apksigner.bat' with args 'verify,--print-certs,E:\FRONT\nodejs\node_gobal\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-debug-androidTest.apk'
[debug] [ADB] 'E:\FRONT\nodejs\node_gobal\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-debug-androidTest.apk' is already signed.
[debug] [ADB] Getting install status for io.appium.uiautomator2.server
[debug] [ADB] Running 'F:\android-sdk\android-sdk\platform-tools\adb.exe -P 5037 -s 192.168.35.101:5555 shell pm list packages io.appium.uiautomator2.server'
[debug] [ADB] App is installed
[debug] [ADB] Getting package info for 'io.appium.uiautomator2.server'
[debug] [ADB] Running 'F:\android-sdk\android-sdk\platform-tools\adb.exe -P 5037 -s 192.168.35.101:5555 shell dumpsys package io.appium.uiautomator2.server'
[ADB] Checking whether aapt is present
[ADB] Using aapt.exe from F:\android-sdk\android-sdk\build-tools\28.0.3\aapt.exe
[debug] [ADB] The installed 'io.appium.uiautomator2.server' package does not require upgrade ('1.12.0' >= '1.12.0')
[debug] [ADB] Getting install status for io.appium.uiautomator2.server.test
[debug] [ADB] Running 'F:\android-sdk\android-sdk\platform-tools\adb.exe -P 5037 -s 192.168.35.101:5555 shell pm list packages io.appium.uiautomator2.server.test'
[debug] [ADB] App is installed
[debug] [ADB] Getting package info for 'io.appium.uiautomator2.server.test'
[debug] [ADB] Running 'F:\android-sdk\android-sdk\platform-tools\adb.exe -P 5037 -s 192.168.35.101:5555 shell dumpsys package io.appium.uiautomator2.server.test'
[ADB] Cannot read version codes of 'E:\FRONT\nodejs\node_gobal\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-debug-androidTest.apk' and/or 'io.appium.uiautomator2.server.test'
[ADB] Cannot read version names of 'E:\FRONT\nodejs\node_gobal\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-debug-androidTest.apk' and/or 'io.appium.uiautomator2.server.test'. Assuming correct app version is already installed
[debug] [UiAutomator2] Waiting up to 20000ms for instrumentation 'io.appium.uiautomator2.server.test/android.support.test.runner.AndroidJUnitRunner' to be available
[debug] [ADB] Running 'F:\android-sdk\android-sdk\platform-tools\adb.exe -P 5037 -s 192.168.35.101:5555 shell pm list instrumentation'
[debug] [UiAutomator2] Instrumentation 'io.appium.uiautomator2.server.test/android.support.test.runner.AndroidJUnitRunner' available
[debug] [ADB] Running 'F:\android-sdk\android-sdk\platform-tools\adb.exe -P 5037 -s 192.168.35.101:5555 wait-for-device'
[debug] [ADB] Running 'F:\android-sdk\android-sdk\platform-tools\adb.exe -P 5037 -s 192.168.35.101:5555 shell echo ping'
[debug] [AndroidDriver] Pushing settings apk to device...
[debug] [ADB] Getting install status for io.appium.settings
[debug] [ADB] Running 'F:\android-sdk\android-sdk\platform-tools\adb.exe -P 5037 -s 192.168.35.101:5555 shell pm list packages io.appium.settings'
[debug] [ADB] App is installed
[debug] [ADB] Getting package info for 'io.appium.settings'
[debug] [ADB] Running 'F:\android-sdk\android-sdk\platform-tools\adb.exe -P 5037 -s 192.168.35.101:5555 shell dumpsys package io.appium.settings'
[debug] [ADB] The installed 'io.appium.settings' package does not require upgrade ('2.3.0' >= '2.3.0')
[debug] [ADB] Running 'F:\android-sdk\android-sdk\platform-tools\adb.exe -P 5037 -s 192.168.35.101:5555 shell ps'
[debug] [AndroidDriver] io.appium.settings is already running. There is no need to reset its permissions.
[debug] [ADB] Device API level: 28
[debug] [ADB] Running 'F:\android-sdk\android-sdk\platform-tools\adb.exe -P 5037 -s 192.168.35.101:5555 shell appops set io.appium.settings android:mock_location allow'
[AndroidDriver] setDeviceLanguageCountry requires language or country.
[AndroidDriver] Got language: 'null' and country: 'null'
[debug] [Logcat] Starting logcat capture
[debug] [AndroidDriver] Enabling Unicode keyboard support
[debug] [AndroidDriver] Pushing unicode ime to device...
[debug] [ADB] Running 'F:\android-sdk\android-sdk\platform-tools\adb.exe -P 5037 -s 192.168.35.101:5555 install E:\FRONT\nodejs\node_gobal\node_modules\appium\node_modules\appium-android-ime\bin\UnicodeIME-debug.apk'
[debug] [ADB] Install command stdout: Success
[debug] [ADB] Running 'F:\android-sdk\android-sdk\platform-tools\adb.exe -P 5037 -s 192.168.35.101:5555 shell settings get secure default_input_method'
[debug] [AndroidDriver] Unsetting previous IME io.appium.android.ime/.UnicodeIME
[debug] [AndroidDriver] Setting IME to 'io.appium.android.ime/.UnicodeIME'
[debug] [ADB] Running 'F:\android-sdk\android-sdk\platform-tools\adb.exe -P 5037 -s 192.168.35.101:5555 shell ime enable io.appium.android.ime/.UnicodeIME'
[debug] [ADB] Running 'F:\android-sdk\android-sdk\platform-tools\adb.exe -P 5037 -s 192.168.35.101:5555 shell ime set io.appium.android.ime/.UnicodeIME'
[debug] [AndroidDriver] Pushing unlock helper app to device...
[debug] [ADB] Getting install status for io.appium.unlock
[debug] [ADB] Running 'F:\android-sdk\android-sdk\platform-tools\adb.exe -P 5037 -s 192.168.35.101:5555 shell pm list packages io.appium.unlock'
[debug] [ADB] App is installed
[debug] [ADB] Getting package info for 'io.appium.unlock'
[debug] [ADB] Running 'F:\android-sdk\android-sdk\platform-tools\adb.exe -P 5037 -s 192.168.35.101:5555 shell dumpsys package io.appium.unlock'
[debug] [ADB] The installed 'io.appium.unlock' package does not require upgrade ('2.0.0' >= '2.0.0')
[debug] [UiAutomator2] Forwarding UiAutomator2 Server port 6790 to 8201
[debug] [ADB] Forwarding system: 8201 to device: 6790
[debug] [ADB] Running 'F:\android-sdk\android-sdk\platform-tools\adb.exe -P 5037 -s 192.168.35.101:5555 forward tcp:8201 tcp:6790'
[debug] [ADB] Running 'F:\android-sdk\android-sdk\platform-tools\adb.exe -P 5037 -s 192.168.35.101:5555 shell rm -rf /data/local/tmp/strings.json'
[debug] [AndroidDriver] Extracting strings from apk
[debug] [AndroidDriver] F:/GsoSiAutomatedTesting/GaoSiAutomatedTesting/app/app-release.apk
[debug] [AndroidDriver] null
[debug] [AndroidDriver] C:\Users\FJY\AppData\Local\Temp\gaosi.com.jion
[debug] [ADB] Extracting strings for language: default
[ADB] Successfully extracted 506 strings from 'F:/GsoSiAutomatedTesting/GaoSiAutomatedTesting/app/app-release.apk' resources for '(default)' configuration
[debug] [ADB] Running 'F:\android-sdk\android-sdk\platform-tools\adb.exe -P 5037 -s 192.168.35.101:5555 push C:\Users\FJY\AppData\Local\Temp\gaosi.com.jion\strings.json /data/local/tmp'
[debug] [ADB] Checking app cert for F:/GsoSiAutomatedTesting/GaoSiAutomatedTesting/app/app-release.apk
[debug] [ADB] Starting 'F:\android-sdk\android-sdk\build-tools\28.0.3\apksigner.bat' with args 'verify,--print-certs,F:/GsoSiAutomatedTesting/GaoSiAutomatedTesting/app/app-release.apk'
[debug] [ADB] 'F:/GsoSiAutomatedTesting/GaoSiAutomatedTesting/app/app-release.apk' is already signed.
[debug] [ADB] Getting install status for gaosi.com.jion
[debug] [ADB] Running 'F:\android-sdk\android-sdk\platform-tools\adb.exe -P 5037 -s 192.168.35.101:5555 shell pm list packages gaosi.com.jion'
[debug] [ADB] App is installed
[debug] [ADB] Getting package info for 'gaosi.com.jion'
[debug] [ADB] Running 'F:\android-sdk\android-sdk\platform-tools\adb.exe -P 5037 -s 192.168.35.101:5555 shell dumpsys package gaosi.com.jion'
[debug] [ADB] The installed 'gaosi.com.jion' package does not require upgrade ('2.3.2' >= '2.3.2')
[debug] [ADB] Running 'F:\android-sdk\android-sdk\platform-tools\adb.exe -P 5037 -s 192.168.35.101:5555 shell am force-stop io.appium.uiautomator2.server'
[UiAutomator2] Starting uiautomator2 server 1.12.0
[UiAutomator2] Using UIAutomator2 server from 'E:\FRONT\nodejs\node_gobal\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-v1.12.0.apk' and test from 'E:\FRONT\nodejs\node_gobal\node_modules\appium\node_modules\appium-uiautomator2-server\apks\appium-uiautomator2-server-debug-androidTest.apk'
[UiAutomator2] Running command: 'adb -s 192.168.35.101:5555 shell am instrument -w io.appium.uiautomator2.server.test/android.support.test.runner.AndroidJUnitRunner'
[UiAutomator2] Waiting up to 20000ms for UiAutomator2 to be online...
[debug] [JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8201/wd/hub/status] with no body
[debug] [JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8201/wd/hub/status] with no body
[debug] [JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8201/wd/hub/status] with no body
[debug] [JSONWP Proxy] Proxying [GET /status] to [GET http://localhost:8201/wd/hub/status] with no body
[debug] [JSONWP Proxy] Got response with status 200: "{\"sessionId\":\"SESSIONID\",\"status\":0,\"value\":\"Status Invoked\"}"
[debug] [JSONWP Proxy] Proxying [POST /session] to [POST http://localhost:8201/wd/hub/session] with body: {"desiredCapabilities":{"platform":"LINUX","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"platformName":"Android","automationName":"UIautomator2","platformVersion":"9","deviceName":"192.168.35.101:5555","app":"F:/GsoSiAutomatedTesting/GaoSiAutomatedTesting/app/app-release.apk","noReset":true,"appPackage":"gaosi.com.jion","appActivity":"gaosi.com.jion.studentapp.loading.SplashingActivity","resetKeyboard":true,"unicodeKeyboard":true,"newCommandTimeout":60},"platformName":"Android","automationName":"UIautomator2","platformVersion":"9","deviceName":"192.168.35.101:5555","app":"F:/GsoSiAutomatedTesting/GaoSiAutomatedTesting/app/app-release.apk","noReset":true,"appPackage":"gaosi.com.jion","appActivity":"gaosi.com.jion.studentapp.loading.SplashingActivity","resetKeyboard":true,"unicodeKeyboard":true,"newCommandTimeout":60,"deviceUDID":"192.168.35.101:5555","deviceScreenSize"...
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"ce55d588-27dd-40e0-8982-dadce86ed567","status":0,"value":"Created Session"}
[debug] [ADB] Running 'F:\android-sdk\android-sdk\platform-tools\adb.exe -P 5037 -s 192.168.35.101:5555 shell dumpsys window'
[AndroidDriver] Screen already unlocked, doing nothing
[UiAutomator2] UiAutomator2 did not start the activity we were waiting for, 'gaosi.com.jion/gaosi.com.jion.studentapp.loading.SplashingActivity'. Starting it ourselves
[debug] [ADB] Device API level: 28
[debug] [ADB] Running 'F:\android-sdk\android-sdk\platform-tools\adb.exe -P 5037 -s 192.168.35.101:5555 shell am start -W -n gaosi.com.jion/gaosi.com.jion.studentapp.loading.SplashingActivity -S -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -f 0x10200000'
[debug] [JSONWP Proxy] Proxying [GET /appium/device/pixel_ratio] to [GET http://localhost:8201/wd/hub/session/ce55d588-27dd-40e0-8982-dadce86ed567/appium/device/pixel_ratio] with body: {}
[debug] [JSONWP Proxy] Got response with status 200: "{\"sessionId\":\"ce55d588-27dd-40e0-8982-dadce86ed567\",\"status\":0,\"value\":2.625}"
[debug] [JSONWP Proxy] Proxying [GET /appium/device/system_bars] to [GET http://localhost:8201/wd/hub/session/ce55d588-27dd-40e0-8982-dadce86ed567/appium/device/system_bars] with body: {}
[debug] [JSONWP Proxy] Got response with status 200: "{\"sessionId\":\"ce55d588-27dd-40e0-8982-dadce86ed567\",\"status\":0,\"value\":{\"statusBar\":63}}"
[debug] [JSONWP Proxy] Proxying [GET /window/current/size] to [GET http://localhost:8201/wd/hub/session/ce55d588-27dd-40e0-8982-dadce86ed567/window/current/size] with body: {}
[debug] [JSONWP Proxy] Got response with status 200: "{\"sessionId\":\"ce55d588-27dd-40e0-8982-dadce86ed567\",\"status\":0,\"value\":{\"height\":1794,\"width\":1080}}"
[Appium] New AndroidUiautomator2Driver session created successfully, session 2c22dbfc-a330-4d5b-af88-43596692a899 added to master session list
[debug] [BaseDriver] Event 'newSessionStarted' logged at 1577161472500 (12:24:32 GMT+0800 (GMT+08:00))
[debug] [W3C] Responding to client with driver.createSession() result: {"capabilities":{"platform":"LINUX","webStorageEnabled":false,"takesScreenshot":true,"javascriptEnabled":true,"databaseEnabled":false,"networkConnectionEnabled":true,"locationContextEnabled":false,"warnings":{},"desired":{"platformName":"Android","automationName":"UIautomator2","platformVersion":"9","deviceName":"192.168.35.101:5555","app":"F:/GsoSiAutomatedTesting/GaoSiAutomatedTesting/app/app-release.apk","noReset":true,"appPackage":"gaosi.com.jion","appActivity":"gaosi.com.jion.studentapp.loading.SplashingActivity","resetKeyboard":true,"unicodeKeyboard":true,"newCommandTimeout":60},"platformName":"Android","automationName":"UIautomator2","platformVersion":"9","deviceName":"192.168.35.101:5555","app":"F:/GsoSiAutomatedTesting/GaoSiAutomatedTesting/app/app-release.apk","noReset":true,"appPackage":"gaosi.com.jion","appActivity":"gaosi.com.jion.studentapp.loading.SplashingActivity","resetKeyboard":true,"unicodeKeyboard":true,"newCommandTimeout":60,"deviceUDID":"192.168.35.101:5555","deviceScreenSize":"1080x...
[HTTP] <-- POST /wd/hub/session 200 47314 ms - 1288
[HTTP]
[HTTP] --> POST /wd/hub/session/2c22dbfc-a330-4d5b-af88-43596692a899/timeouts
[HTTP] {"implicit":10000}
[debug] [W3C] Calling AppiumDriver.timeouts() with args: [{"protocol":"W3C","implicit":10000},"2c22dbfc-a330-4d5b-af88-43596692a899"]
[debug] [BaseDriver] script: undefined, pageLoad: undefined, implicit: 10000
[debug] [BaseDriver] Set implicit wait to 10000ms
[debug] [W3C] Responding to client with driver.timeouts() result: null
[HTTP] <-- POST /wd/hub/session/2c22dbfc-a330-4d5b-af88-43596692a899/timeouts 200 2252 ms - 14
[HTTP]
[HTTP] --> POST /wd/hub/session/2c22dbfc-a330-4d5b-af88-43596692a899/element
[HTTP] {"using":"id","value":"tv_subject_title"}
[debug] [W3C] Calling AppiumDriver.findElement() with args: ["id","tv_subject_title","2c22dbfc-a330-4d5b-af88-43596692a899"]
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[debug] [BaseDriver] Waiting up to 10000 ms for condition
[debug] [JSONWP Proxy] Proxying [POST /element] to [POST http://localhost:8201/wd/hub/session/ce55d588-27dd-40e0-8982-dadce86ed567/element] with body: {"strategy":"id","selector":"tv_subject_title","context":"","multiple":false}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"ce55d588-27dd-40e0-8982-dadce86ed567","status":0,"value":{"ELEMENT":"e72991d2-bb41-472a-a156-62666dd20b67"}}
[debug] [W3C] Responding to client with driver.findElement() result: {"element-6066-11e4-a52e-4f735466cecf":"e72991d2-bb41-472a-a156-62666dd20b67"}
[HTTP] <-- POST /wd/hub/session/2c22dbfc-a330-4d5b-af88-43596692a899/element 200 358 ms - 88
[HTTP]
[HTTP] --> POST /wd/hub/session/2c22dbfc-a330-4d5b-af88-43596692a899/element/e72991d2-bb41-472a-a156-62666dd20b67/click
[HTTP] {"id":"e72991d2-bb41-472a-a156-62666dd20b67"}
[debug] [W3C] Calling AppiumDriver.click() with args: ["e72991d2-bb41-472a-a156-62666dd20b67","2c22dbfc-a330-4d5b-af88-43596692a899"]
[debug] [JSONWP Proxy] Proxying [POST /element/e72991d2-bb41-472a-a156-62666dd20b67/click] to [POST http://localhost:8201/wd/hub/session/ce55d588-27dd-40e0-8982-dadce86ed567/element/e72991d2-bb41-472a-a156-62666dd20b67/click] with body: {"element":"e72991d2-bb41-472a-a156-62666dd20b67"}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"ce55d588-27dd-40e0-8982-dadce86ed567","status":0,"value":true}
[debug] [W3C] Responding to client with driver.click() result: true
[HTTP] <-- POST /wd/hub/session/2c22dbfc-a330-4d5b-af88-43596692a899/element/e72991d2-bb41-472a-a156-62666dd20b67/click 200 40 ms - 14
[HTTP]
[HTTP] --> POST /wd/hub/session/2c22dbfc-a330-4d5b-af88-43596692a899/elements
[HTTP] {"using":"id","value":"item_linear"}
[debug] [W3C] Calling AppiumDriver.findElements() with args: ["id","item_linear","2c22dbfc-a330-4d5b-af88-43596692a899"][debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[debug] [BaseDriver] Waiting up to 10000 ms for condition
[debug] [JSONWP Proxy] Proxying [POST /elements] to [POST http://localhost:8201/wd/hub/session/ce55d588-27dd-40e0-8982-dadce86ed567/elements] with body: {"strategy":"id","selector":"item_linear","context":"","multiple":true}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"ce55d588-27dd-40e0-8982-dadce86ed567","status":0,"value":[{"ELEMENT":"79f0b1ae-532f-418a-a918-084750bdd257"},{"ELEMENT":"165d6e81-979b-488d-bd78-02126facb39c"},{"ELEMENT":"2952cad6-d664-4393-a8ee-9e1e8ec772d3"},{"ELEMENT":"124664db-165a-4ed4-b4a0-a2f1c6f3d9dd"},{"ELEMENT":"6729ab73-38e9-49dc-8f30-1c8eb6dc568a"},{"ELEMENT":"963f7948-9ea1-4862-91ed-b738c96e1bbb"}]}
[debug] [W3C] Responding to client with driver.findElements() result: [{"element-6066-11e4-a52e-4f735466cecf":"79f0b1ae-532f-418a-a918-084750bdd257"},{"element-6066-11e4-a52e-4f735466cecf":"165d6e81-979b-488d-bd78-02126facb39c"},{"element-6066-11e4-a52e-4f735466cecf":"2952cad6-d664-4393-a8ee-9e1e8ec772d3"},{"element-6066-11e4-a52e-4f735466cecf":"124664db-165a-4ed4-b4a0-a2f1c6f3d9dd"},{"element-6066-11e4-a52e-4f735466cecf":"6729ab73-38e9-49dc-8f30-1c8eb6dc568a"},{"element-6066-11e4-a52e-4f735466cecf":"963f7948-9ea1-4862-91ed-b738c96e1bbb"}]
[HTTP] <-- POST /wd/hub/session/2c22dbfc-a330-4d5b-af88-43596692a899/elements 200 808 ms - 485
[HTTP]
[HTTP] --> POST /wd/hub/session/2c22dbfc-a330-4d5b-af88-43596692a899/element/79f0b1ae-532f-418a-a918-084750bdd257/click
[HTTP] {"id":"79f0b1ae-532f-418a-a918-084750bdd257"}
[debug] [W3C] Calling AppiumDriver.click() with args: ["79f0b1ae-532f-418a-a918-084750bdd257","2c22dbfc-a330-4d5b-af88-43596692a899"]
[debug] [JSONWP Proxy] Proxying [POST /element/79f0b1ae-532f-418a-a918-084750bdd257/click] to [POST http://localhost:8201/wd/hub/session/ce55d588-27dd-40e0-8982-dadce86ed567/element/79f0b1ae-532f-418a-a918-084750bdd257/click] with body: {"element":"79f0b1ae-532f-418a-a918-084750bdd257"}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"ce55d588-27dd-40e0-8982-dadce86ed567","status":0,"value":true}
[debug] [W3C] Responding to client with driver.click() result: true
[HTTP] <-- POST /wd/hub/session/2c22dbfc-a330-4d5b-af88-43596692a899/element/79f0b1ae-532f-418a-a918-084750bdd257/click 200 50 ms - 14
[HTTP]
[HTTP] --> POST /wd/hub/session/2c22dbfc-a330-4d5b-af88-43596692a899/element
[HTTP] {"using":"id","value":"tv_subject_title"}
[debug] [W3C] Calling AppiumDriver.findElement() with args: ["id","tv_subject_title","2c22dbfc-a330-4d5b-af88-43596692a899"]
[debug] [BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[debug] [BaseDriver] Waiting up to 10000 ms for condition
[debug] [JSONWP Proxy] Proxying [POST /element] to [POST http://localhost:8201/wd/hub/session/ce55d588-27dd-40e0-8982-dadce86ed567/element] with body: {"strategy":"id","selector":"tv_subject_title","context":"","multiple":false}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"ce55d588-27dd-40e0-8982-dadce86ed567","status":0,"value":{"ELEMENT":"a7d9ff2f-c207-442d-aa23-2c50f1ea36ff"}}
[debug] [W3C] Responding to client with driver.findElement() result: {"element-6066-11e4-a52e-4f735466cecf":"a7d9ff2f-c207-442d-aa23-2c50f1ea36ff"}
[HTTP] <-- POST /wd/hub/session/2c22dbfc-a330-4d5b-af88-43596692a899/element 200 835 ms - 88
[HTTP]
[HTTP] --> POST /wd/hub/session/2c22dbfc-a330-4d5b-af88-43596692a899/element/a7d9ff2f-c207-442d-aa23-2c50f1ea36ff/click
[HTTP] {"id":"a7d9ff2f-c207-442d-aa23-2c50f1ea36ff"}
[debug] [W3C] Calling AppiumDriver.click() with args: ["a7d9ff2f-c207-442d-aa23-2c50f1ea36ff","2c22dbfc-a330-4d5b-af88-43596692a899"]
[debug] [JSONWP Proxy] Proxying [POST /element/a7d9ff2f-c207-442d-aa23-2c50f1ea36ff/click] to [POST http://localhost:8201/wd/hub/session/ce55d588-27dd-40e0-8982-dadce86ed567/element/a7d9ff2f-c207-442d-aa23-2c50f1ea36ff/click] with body: {"element":"a7d9ff2f-c207-442d-aa23-2c50f1ea36ff"}
[debug] [JSONWP Proxy] Got response with status 200: {"sessionId":"ce55d588-27dd-40e0-8982-dadce86ed567","status":0,"value":true}
[debug] [W3C] Responding to client with driver.click() result: true
[HTTP] <-- POST /wd/hub/session/2c22dbfc-a330-4d5b-af88-43596692a899/element/a7d9ff2f-c207-442d-aa23-2c50f1ea36ff/click 200 29 ms - 14
[HTTP]
[HTTP] --> POST /wd/hub/session/2c22dbfc-a330-4d5b-af88-43596692a899/element/165d6e81-979b-488d-bd78-02126facb39c/click
[HTTP] {"id":"165d6e81-979b-488d-bd78-02126facb39c"}
[debug] [W3C] Calling AppiumDriver.click() with args: ["165d6e81-979b-488d-bd78-02126facb39c","2c22dbfc-a330-4d5b-af88-43596692a899"]
[debug] [JSONWP Proxy] Proxying [POST /element/165d6e81-979b-488d-bd78-02126facb39c/click] to [POST http://localhost:8201/wd/hub/session/ce55d588-27dd-40e0-8982-dadce86ed567/element/165d6e81-979b-488d-bd78-02126facb39c/click] with body: {"element":"165d6e81-979b-488d-bd78-02126facb39c"}
[W3C] Encountered internal error running command: {"w3cStatus":400,"jsonwp":{"sessionId":"ce55d588-27dd-40e0-8982-dadce86ed567","status":10,"value":"android.support.test.uiautomator.StaleObjectException\n\tat android.support.test.uiautomator.UiObject2.getAccessibilityNodeInfo(UiObject2.java:629)\n\tat android.support.test.uiautomator.UiObject2.getVisibleBounds(UiObject2.java:210)\n\tat android.support.test.uiautomator.UiObject2.getVisibleCenter(UiObject2.java:251)\n\tat android.support.test.uiautomator.UiObject2.click(UiObject2.java:343)\n\tat io.appium.uiautomator2.model.UiObject2Element.click(UiObject2Element.java:64)\n\tat io.appium.uiautomator2.handler.Click.safeHandle(Click.java:38)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:65)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:247)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:238)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:44)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)\n\tat io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)\n\tat io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:435)\n\tat io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)\n\tat io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)\n\tat io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:250)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)\n\tat io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1294)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:911)\n\tat io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)\n\tat io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:611)\n\tat io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:552)\n\tat io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:466)\n\tat io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:438)\n\tat io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140)\n\tat io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)\n\tat java.lang.Thread.run(Thread.java:764)\n"}} ProxyRequestError: Could not proxy command to remote server. Original error: 500 - {"sessionId":"ce55d588-27dd-40e0-8982-dadce86ed567","status":10,"value":"android.support.test.uiautomator.StaleObjectException\n\tat android.support.test.uiautomator.UiObject2.getAccessibilityNodeInfo(UiObject2.java:629)\n\tat android.support.test.uiautomator.UiObject2.getVisibleBounds(UiObject2.java:210)\n\tat android.support.test.uiautomator.UiObject2.getVisibleCenter(UiObject2.java:251)\n\tat android.support.test.uiautomator.UiObject2.click(UiObject2.java:343)\n\tat io.appium.uiautomator2.model.UiObject2Element.click(UiObject2Element.java:64)\n\tat io.appium.uiautomator2.handler.Click.safeHandle(Click.java:38)\n\tat io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:65)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:247)\n\tat io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:238)\n\tat io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:44)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)\n\tat io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)\n\tat io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:435)\n\tat io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)\n\tat io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)\n\tat io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:250)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)\n\tat io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1294)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)\n\tat io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)\n\tat io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:911)\n\tat io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)\n\tat io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:611)\n\tat io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:552)\n\tat io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:466)\n\tat io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:438)\n\tat io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140)\n\tat io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)\n\tat java.lang.Thread.run(Thread.java:764)\n"}
[W3C] at JWProxy.proxy$ (E:\FRONT\nodejs\node_gobal\node_modules\appium\node_modules\appium-base-driver\lib\jsonwp-proxy\proxy.js:152:13)
[W3C] at tryCatch (E:\FRONT\nodejs\node_gobal\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:67:40)
[W3C] at GeneratorFunctionPrototype.invoke as _invoke
[W3C] at GeneratorFunctionPrototype.prototype.(anonymous function) as throw
[W3C] at GeneratorFunctionPrototype.invoke (E:\FRONT\nodejs\node_gobal\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:136:37)
[debug] [MJSONWP] Matched JSONWP error code 10 to StaleElementReferenceError
[HTTP] <-- POST /wd/hub/session/2c22dbfc-a330-4d5b-af88-43596692a899/element/165d6e81-979b-488d-bd78-02126facb39c/click 404 99 ms - 8288
[HTTP]

共收到 6 条回复 时间 点赞

升级下你的 appium 版本

wtnhz 回复

是不兼容的问题吗 我用的是 appium sever 启动的,升到哪个版本好呢

升级 appium 到 1.14.0 后部分脚本可以执行,但遇到遍历脚本时都报这个错误
[MJSONWP] Matched JSONWP error code 10 to StaleElementReferenceError
[debug] [W3C (c7a85ee6)] Encountered internal error running command: StaleElementReferenceError: io.appium.uiautomator2.common.exceptions.StaleElementReferenceException: Cached elements 'By.id: item_linear' do not exist in DOM anymore

拜托论坛里各位老师帮我看看是什么问题,好几天了都没解决,换了很多 appium 版本 使用 UIautomator2 脚本就报 Encountered internal error running command:StaleElementReferenceError:io.appium.uiautomator2.common.exceptions.StaleElementReferenceException: Cached elements 'By.id: item_linear' do not exist in DOM anymore。
不使用 UIautomator2 脚本顺利执行,求帮助~

以后有问题可以先去这里找找 https://github.com/appium/appium/issues
然后你这个问题的答案在这里 https://github.com/appium/appium/issues/13505

大概意思就是:UIA2 无法定位缓存的元素,因为对该元素的引用已失效。每次要访问此类实体时都必须调用 findElement,而不是遍历已缓存的列表

然后我看了下你的代码,大概是先拿到一个列表的元素,然后是去遍历点击各个 item,我想问的是 你这里点击了 item 是不是跳转到其它页面了,然后到了那个页面你又点击了返回什么的回到这个列表页面,在点击第二个列表~ 是不是?
如果是的话~在你返回到列表界面之后可能就找不到元素了 要重新去获取列表的元素~

# try里直接改成这样子试下
....
try:
    self.Subject_id_index=desired_caps.driver.find_elements_by_id(find_course_selection_id.Item_linear)[Subject_index]
exceptNoSuchElementException:
  .....
wtnhz 回复

感谢老师回答 我研究一下 谢谢

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册