appium(五)常用方法
1、在使用appium时,经常会用到adb命令,我们可以使用以下方法来调用adb,如下例调用adb滑动屏幕
String cmd="cmd /c start adb shell input swipe X0,Y0,X1,Y1,TIME ";
Runtime.getRuntime().exec(cmd);
2、使用appium的方法,使用坐标进行滑动屏幕
TouchAction action = new TouchAction(driver); //设置起点和终点 PointOption pressPoint=PointOption.point(x, y); PointOption movePoint=PointOption.point(x1, y1); //滑动 action.longPress(pressPoint).moveTo(movePoint).release().perform();
3、使用appium的方法,使用坐标点击
TouchAction action = new TouchAction(driver); PointOption pressPoint=PointOption.point(x, y); //点击 action.tap(pressPoint).release().perform();
4、使用appium的方法,长按某个坐标
TouchAction action = new TouchAction(driver); PointOption pressPoint=PointOption.point(x, y); //设置长按的时间 Duration last = Duration.ofSeconds(t); WaitOptions wait= WaitOptions.waitOptions(last); //长按坐标 action.longPress(pressPoint).waitAction(wait).perform();
5、使用appium的方法,长按某个元素
Duration last = Duration.ofSeconds(t); TouchAction action = new TouchAction(driver); //定位到一个元素,并且在该元素上长按指定的时长 action.longPress(LongPressOptions.longPressOptions().withElement(ElementOption.element(driver.findElementByXPath(xpath))).withDuration(last)).waitAction(WaitOptions.waitOptions(last)).perform();
6、appium的其他方法,可以参考 TouchAction 的源码
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具