问题:打开微信连续侧滑,第一页可以滑动,到第二页再滑动就报错
部分代码:

@driver= Appium::Driver.new(caps)
@touch = Appium::TouchAction.new
@dirver.start_driver
@touch.swipe(start_x:1000,start_y:300,end_x:300,end_y:300,duration:1000).perform
@touch.swipe(start_x:1000,start_y:300,end_x:300,end_y:300,duration:1000).perform

日志:
{"version":"1.4.16","revision":"ae6877eff263066b26328d457bd285c0cc62430d"}},"sessionId":"c19b459b-8c06-4ee4-9de4-f4c25a483bdf"}

info: --> POST /wd/hub/session/c19b459b-8c06-4ee4-9de4-f4c25a483bdf/timeouts/implicit_wait {"ms":0}
info: [debug] Set Android implicit wait to 0ms
info: [debug] Responding to client with success: {"status":0,"value":null,"sessionId":"c19b459b-8c06-4ee4-9de4-f4c25a483bdf"}
info: <-- POST /wd/hub/session/c19b459b-8c06-4ee4-9de4-f4c25a483bdf/timeouts/implicit_wait 200 0.791 ms - 76 {"status":0,"value":null,"sessionId":"c19b459b-8c06-4ee4-9de4-f4c25a483bdf"}
info: --> POST /wd/hub/session/c19b459b-8c06-4ee4-9de4-f4c25a483bdf/touch/perform {"actions":[{"action":"press","options":{"x":1000,"y":300}},{"action":"wait","options":{"ms":200}},{"action":"moveTo","options":{"x":300,"y":300}},{"action":"release"}]}
info: [debug] Pushing command to appium work queue: ["swipe",{"startX":1000,"startY":300,"endX":300,"endY":300,"steps":6}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"swipe","params":{"startX":1000,"startY":300,"endX":300,"endY":300,"steps":6}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: swipe
info: [debug] [BOOTSTRAP] [debug] Display bounds: [0,0][1440,2560]
info: [debug] [BOOTSTRAP] [debug] Display bounds: [0,0][1440,2560]
info: [debug] [BOOTSTRAP] [debug] Swiping from [x=1000.0, y=300.0] to [x=300.0, y=300.0] with steps: 6
info: [debug] [BOOTSTRAP] [debug] Returning result: {"status":0,"value":true}
info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"c19b459b-8c06-4ee4-9de4-f4c25a483bdf"}
info: <-- POST /wd/hub/session/c19b459b-8c06-4ee4-9de4-f4c25a483bdf/touch/perform 200 195.217 ms - 76 {"status":0,"value":true,"sessionId":"c19b459b-8c06-4ee4-9de4-f4c25a483bdf"}
info: --> POST /wd/hub/session/c19b459b-8c06-4ee4-9de4-f4c25a483bdf/touch/perform {"actions":[{"action":"press","options":{"x":1000,"y":300}},{"action":"wait","options":{"ms":200}},{"action":"moveTo","options":{"x":300,"y":300}},{"action":"release"},{"action":"press","options":{"x":1000,"y":300}},{"action":"wait","options":{"ms":200}},{"action":"moveTo","options":{"x":300,"y":300}},{"action":"release"}]}
info: <-- POST /wd/hub/session/c19b459b-8c06-4ee4-9de4-f4c25a483bdf/touch/perform 500 2.852 ms - 97
TypeError: Cannot read property 'element' of undefined
at C:\Program Files (x86)\Appium\node_modules\appium\lib\devices\android\android-controller.js:937:20
at C:\Program Files (x86)\Appium\node_modules\appium\node_modules\underscore\underscore.js:227:11
at Function..each..forEach (C:\Program Files (x86)\Appium\node_modules\appium\node_modules\underscore\underscore.js:153:9)
at Function..filter..select (C:\Program Files (x86)\Appium\node_modules\appium\node_modules\underscore\underscore.js:226:7)
at [object Object]._.(anonymous function) as filter

我分析第二次滑动失败,是因为(日志)

info: --> POST /wd/hub/session/c19b459b-8c06-4ee4-9de4-f4c25a483bdf/touch/perform {"actions":[{"action":"press","options":{"x":1000,"y":300}},{"action":"wait","options":{"ms":200}},{"action":"moveTo","options":{"x":300,"y":300}},{"action":"release"},{"action":"press","options":{"x":1000,"y":300}},{"action":"wait","options":{"ms":200}},{"action":"moveTo","options":{"x":300,"y":300}},{"action":"release"}]}
跟第一次(日志)相比多了
{"action":"press","options":{"x":1000,"y":300}},{"action":"wait","options":{"ms":200}},{"action":"moveTo","options":{"x":300,"y":300}},{"action":"release"}
导致服务不响应

尝试过的解决办法:
1.延长等待以及程序睡眠时间
2.升级 appium_lib 到最新版

问题依然存在,哪位同学也碰到过这样的问题,求分享!


↙↙↙阅读原文可查看相关链接,并与作者交流