默认页面是酱紫的:
然后上拉会有一个 button 出来:
然后下滑也会有一个 button 出来:
上拉我用 scroll_to "GO TO NEXT LEVEL" 就解决了
下滑的这个就不管用了:
scroll_to "GO TO PREVIOUS LEVEL" appium server
—— 找不到 "GO TO PREVIOUS LEVEL"
swipe start_x: 50, start_y: 0, end_x: 50, end_y: 200, duration: 2
—— 结果是横向移动了
swipe start_x: 0, start_y: 50, end_x: 200, end_y: 50, duration: 2
—— 没有响应
execute_script 'mobile: scroll', :direction => 'down'
—— 找不到 execute_script 方法
环境:appium version 1.4.7, 语言:ruby
参考:https://github.com/appium/ruby_lib/blob/master/docs/android_docs.md
这是 UIAutomator 的原理决定的,不可见元素都抓不到,所以只能滚一次找一次。
#1 楼 @chenhengjie123 现有的方法里面我没有找到现成的可以下滑的方法 所以需要自己封装 但是太弱了 能详细说说封装的吗?
swipe start_x: 50, start_y: 0, end_x: 50, end_y: 200, duration: 2
—— 结果是横向移动了
这个横向移动很奇怪啊,建议起始 y 不要设成 0,试试
@eurekasaber 尝试了 swipe start_x: 50, start_y: 200, end_x: 50, end_y: 400, duration: 2
我在模拟器上没有看到任何变化,我想要下滑但是感觉好像在某个 unit 上横向移动了,unit 上横向移动是没有反应的
log 中显示是成功的:
info: [debug] Pushing command to appium work queue: ["swipe",{"startX":50,"startY":200,"endX":50,"endY":400,"steps":0}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"swipe","params":{"startX":50,"startY":200,"endX":50,"endY":400,"steps":0}}
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][768,1184]
info: [debug] [BOOTSTRAP] [debug] Display bounds: [0,0][768,1184]
info: [debug] [BOOTSTRAP] [debug] Swiping from [x=50.0, y=200.0] to [x=50.0, y=400.0] with steps: 0
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"23cea7bb-f191-4c8e-b645-c45c9ca717d9"}
info: <-- POST /wd/hub/session/23cea7bb-f191-4c8e-b645-c45c9ca717d9/touch/perform 200 36.777 ms - 76 {"status":0,"value":true,"sessionId":"23cea7bb-f191-4c8e-b645-c45c9ca717d9"}
info: --> GET /wd/hub/session/23cea7bb-f191-4c8e-b645-c45c9ca717d9/source {}
info: [debug] Pushing command to appium work queue: ["source",{}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"source","params":{}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: source
@eurekasaber 我还尝试了 swipe start_x: 200, start_y: 200, end_x: 400, end_y: 200, duration: 2
log 也是成功的:
info: [debug] Pushing command to appium work queue: ["swipe",{"startX":200,"startY":200,"endX":400,"endY":200,"steps":0}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"swipe","params":{"startX":200,"startY":200,"endX":400,"endY":200,"steps":0}}
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][768,1184]
info: [debug] [BOOTSTRAP] [debug] Display bounds: [0,0][768,1184]
info: [debug] [BOOTSTRAP] [debug] Swiping from [x=200.0, y=200.0] to [x=400.0, y=200.0] with steps: 0
info: [debug] Responding to client with success: {"status":0,"value":true,"sessionId":"06731e8a-641d-4fbc-904d-c1ebfaec8d05"}
info: <-- POST /wd/hub/session/06731e8a-641d-4fbc-904d-c1ebfaec8d05/touch/perform 200 22.435 ms - 76 {"status":0,"value":true,"sessionId":"06731e8a-641d-4fbc-904d-c1ebfaec8d05"}
info: [debug] [BOOTSTRAP] [debug] Returning result: {"value":true,"status":0}
info: --> GET /wd/hub/session/06731e8a-641d-4fbc-904d-c1ebfaec8d05/source {}
info: [debug] Pushing command to appium work queue: ["source",{}]
info: [debug] [BOOTSTRAP] [debug] Got data from client: {"cmd":"action","action":"source","params":{}}
info: [debug] [BOOTSTRAP] [debug] Got command of type ACTION
info: [debug] [BOOTSTRAP] [debug] Got command action: source
只是看到了屏幕闪了下
#5 楼 @55hhy 不知道你用的是哪个 client ,但从 appium log 看起来你的 steps 好短,相当于瞬移了。。。
duration 一般设 0.5 秒以上吧。某些 client 的 duration 单位是毫秒,这个你最好检查一下。
另外,之前误解你的需求了。。。你需要的不是 scroll to ,只是 scroll 后操作某个元素。方法就是 swipe + find + click 就好了。
另外,startX,startY 这些单位都是 像素,所以需要注意一下你滑动的距离对不对。
android 的开发者选项里有两个显示触摸操作的选项:显示触摸操作 和 指针位置 ,你把这两个都打开然后看看 swipe 具体是滑动了什么地方,然后再调整参数吧。
swipe start_x: 200, start_y: 200, end_x: 400, end_y: 200, duration: 2
你这里从 200 滑动到 400,是页面向上滚动了。。。
解决了 还是用的 swipe start_x: 200, start_y: 200, end_x: 200, end_y: 400, duration: 2000
这里的 duration 单位是 ms 只要时间够长就好了
我也是,后来直接设 1000 就好了
def scrollDownToFind(text)
while true
if not exists { text_exact(text) }
execute_script 'mobile: scroll', direction: 'down'
next
end
found_cell = wait { text_exact(text) }
break
end
found_cell
end
请问是怎么解决的。我用 driver.scrollto(string text) 只能滑动到页面底部