Appium 【自问自答模范帖】Android,chrome 中如何实现滑动,左右滑动

chengaomin · 2014年08月07日 · 最后由 零距离 回复于 2016年03月04日 · 1523 次阅读

用的 appium 1.2.0 版本

1.TouchAction 失败

一开始使用的 TouchAction(driver).press(x=150, y=100).move_to(x=250, y=100).release().perform()
失败,总是 404,查询了一些资料说 chrome 下是不支持 TouchAction 的

2.mobile: swipe 失败

driver.execute_script('mobile: swipe', {'duration': 0.5, 'startX': 100, 'startY': 100, 'endX': 200, 'endY': 100})
失败,报错 ↓

debug: Appium request initiated at /wd/hub/session/76891c298f4443cb292fc608ff4fa211/execute
debug: Request received with params: {"sessionId":"76891c298f4443cb292fc608ff4fa211","args":[{"duration":0.5,"endX":200,"startX":100,"startY":100,"endY":100}],"script":"mobile: swipe"}
debug: Pushing command to appium work queue: ["swipe",{"startX":100,"startY":100,"endX":200,"endY":100,"steps":14}]
error: Unhandled error: TypeError: Cannot call method 'sendAction' of null
at null. (C:\Users\chengaomin\Desktop\Appium\node_modules\appium\lib\devices\android\android.js:459:24)
at Object.q.process as _onImmediate
at processImmediate as _immediateCallback context: [POST /wd/hub/session/76891c298f4443cb292fc608ff4fa211/execute {"duration":0.5,"endX":200,"startX":100,"startY":100,"endY":100,"touchCount":1,"element":null}]

又查了一些资料,有人说 chrome 下也不支持 mobile:tap,swipe 等。不知道是不是真这样

已经解决,看一楼回复

共收到 4 条回复 时间 点赞

只能自问自答了,已经捣鼓出来:
调用 webdriver 自己的触摸事件
from selenium.webdriver.common.touch_actions import TouchActions
TouchActions(driver).tap_and_hold(200, 1000).move(300, 1000).release(300, 1000).perform()

学习啦!

@lihuazhang @chengaomin appium 重新实现了 selenium 的 TouchAction,貌似是 TouchActions 调用的是 appium 的 bootstrap,TouchAction 是用的 chromeDriver,不知道是不是这样,还需要跟源码继续深挖

需要 登录 後方可回應,如果你還沒有帳號按這裡 注册