码迷,mamicode.com
首页 > 移动开发 > 详细

appium(五)常用方法

时间:2020-01-06 00:18:14      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:new   ati   长按   定位   div   appium   滑动   span   art   

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 的源码

appium(五)常用方法

标签:new   ati   长按   定位   div   appium   滑动   span   art   

原文地址:https://www.cnblogs.com/yjh1995/p/12154226.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!