Appium andriod 系统,appium 模拟手势滑动操作问题

lynnfang0917 · 2014年10月13日 · 最后由 大东 回复于 2014年10月13日 · 2649 次阅读

andriod 系统,appium 模拟手势滑动操作问题:

js_snippet = "mobile: swipe"
args = {'startX':100, 'startY':400, 'startX':100, 'startY':200, 'tapCount':1, 'duration':5}
self.driver.execute_script(js_snippet, args)

这样并未能实现从下往上滑动的情形?麻烦各位支招,谢谢

共收到 11 条回复 时间 点赞

错误信息是?

#1 楼 @xiaomayi0323
代码如下:

appium 输出信息:

好奇怪,为什么会变成是从(100,100)到(360,640)?我是昨天才安装使用 appium,初学,请多多指教呢

你先看看你的代码,都是 Start

{'startX':100, 'startY':400, 'startX':100, 'startY':200, 'tapCount':1, 'duration':5}
{'startX':100, 'startY':400, 'endX':100, 'endY':200, 'tapCount':1, 'duration':5}

#3 楼 @xiaomayi0323 嗯,我是从http://www.testerhome.com/topics/167~~~我改成 endX 和 endY 之后就 OK 了学习来的,这个参数我没有注意到,我检讨

另外,因为我起初使用直接调用 driver.swipe 函数,self.driver.swipe(100,300,100,100,100),但是滑动效果没有那么好,而且结束时会点击到我的一个链接,这是为什么呢?是因为我画红框的那个 “action”:“press” 吗?

#4 楼 @anikikun 嗯,xiaomayi0323 已经提醒我了

@lynnfang0917 实在不行,你用 adb shell input swipe 命令吧,os.system("adb shell input swipe 100 400 100 200")

#7 楼 @xuxu 嗯嗯,我修改成 endX 和 endY 之后就可以了,我感觉 def swipe(self, start_x, start_y, end_x, end_y, duration=None):中的 duration 的设置很重要,这个是 ms 级别的,如果设置太小则不起作用

看一下 swipe 的源码,它做了 4 个动作:press、wait、move_to、release
def swipe(self, start_x, start_y, end_x, end_y, duration=None):
"""Swipe from one point to another point, for an optional duration.

:Args:
- start_x - x-coordinate at which to start
- start_y - y-coordinate at which to end
- end_x - x-coordinate at which to stop
- end_y - y-coordinate at which to stop
- duration - (optional) time to take the swipe, in ms.

:Usage:
driver.swipe(100, 100, 100, 400)
"""
# swipe is something like press-wait-move_to-release, which the server
# will translate into the correct action
action = TouchAction(self)
action \
.press(x=start_x, y=start_y) \
.wait(ms=duration) \
.move_to(x=end_x, y=end_y) \
.release()
action.perform()
return self

应该就是那个 press 不小心点击到我 app 页面上的链接了

driver.swipe 的 duration 单位是毫秒,设长一些就不会点开链接了

这个 问题有解决吗

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