• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

java - iOS+appium java客户端: Long press TouchAction does not work?

[复制链接]
菜鸟教程小白 发表于 2022-12-13 12:56:51 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我正在尝试在原生 iOS 应用中自动执行长按触摸操作。

方法1:模拟左上角的长按不起作用。

new TouchAction(driver).longPress(0,0).perform() Appium 日志显示没有错误:

info: [debug] [INST] 2015-12-21 17:41:19 +0000 Debug: Got new command 5 from instruments: target.touch([{"touch":[{"x":0,"y":0}],"time":0.2}])
info: [debug] [INST] 2015-12-21 17:41:19 +0000 Debug: evaluating target.touch([{"touch":[{"x":0,"y":0}],"time":0.2}])
info: [debug] [INST] 2015-12-21 17:41:19 +0000 Debug: target.touch(__NSCFArray)
info: [debug] [INST] 2015-12-21 17:41:20 +0000 Debug: evaluation finished
info: [debug] [INST] 2015-12-21 17:41:20 +0000 Debug: responding with:
info: [debug] [INST] 2015-12-21 17:41:20 +0000 Debug: Running system command #6: /usr/local/Cellar/node/4.1.1/bin/node /usr/local/lib/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{"status":0,"value":""}...
info: [debug] Socket data received (25 bytes)
info: [debug] Socket data being routed.
info: [debug] Got result from instruments: {"status":0,"value":""}
info: [debug] Responding to client with success: {"status":0,"value":"","sessionId":"332523ee-5a1b-427a-8beb-3c150587d08b"}

方法二:执行javascript模拟长按

((IOSDriver)driver).executeScript("mobile: longClick", ImmutableMap.of("x", 5, "y", 5));

Appium 日志异常如下:

TypeError: cb is not a function
    at [object Object].iOSController.touchLongClick (/usr/local/lib/node_modules/appium/lib/devices/ios/ios-controller.js:614:3)
    at Object.exports.touchLongClick [as longClick] (/usr/local/lib/node_modules/appium/lib/server/controller.js:371:16)
    at Object.exports.executeMobileMethod (/usr/local/lib/node_modules/appium/lib/server/controller.js:984:22)
    at exports.execute (/usr/local/lib/node_modules/appium/lib/server/controller.js:940:15)
    at Layer.handle [as handle_request] (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/layer.js:82:5)



Best Answer-推荐答案


您必须将 2 个参数传递给 longPress() 方法。它们是您要保持的元素(下面代码中的元素)和时间(2000 毫秒)它必须保持多长时间。

MobileElement element = driver.findElementByClassName("xxx");
new TouchAction(driver).longPress(element, 2000).perform();

关于java - iOS+appium java客户端: Long press TouchAction does not work?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34401593/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap