Appium 在 ios 7.x 中运行 swipe 代码怎么变成点击操作了呢?请大神解答

云飞凌风 · September 12, 2014 · 1653 hits

我在 ios 7.x 的自动化测试时,发现如下的代码不能够进行滑动下拉刷新操作,反而是进行了点击操作,请大神解答,谢谢。

public void swipeTest() throws InterruptedException {
     String js_snippet = "mobile: swipe";
     JavascriptExecutor js = (JavascriptExecutor) driver;
     HashMap<String, Double> swipeObject = new HashMap<String, Double>();
     swipeObject.put("startx",75.0);
     swipeObject.put("starty",500.0);
     swipeObject.put("endx",75.0);
     swipeObject.put("endy",0.0);
     swipeObject.put("tapCount",1.0);
     swipeObject.put("duration",5.0);
     js.executeScript(js_snippet, swipeObject);
     System.out.println(js_snippet); 
 }
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 18 条回复 时间 点赞

duration 太久了吧? 動作太慢被程式判斷為點擊了 縮短一點試試看?

#1 楼 @gigayaya 缩短为 1 秒还都是一样的,要进行下拉拖拽的效果,才能够进行下拉刷新的。弄了好久了都不行,没有一个方法可行的到现在。

匿名 #3 · September 12, 2014

昨天刚用过,不过我的是 python,屡试不爽,仅供参考

driver.swipe(301,978,301,0) #向上滑动一屏

#3 楼 @link1220 直接就可以在 swipe 方法中填写参数,不行的吧?

匿名 #5 · September 12, 2014

#4 楼 @wangcityboy Java 行不行不知道,,,Python 可以 😌

#5 楼 @link1220 试过了,不行,再说,你给的坐标在我这里会报错,超出范围,苹果的界面,开始坐标哪有 978 的,另外,在 java 中,还有一个参数:Duration

匿名 #7 · September 12, 2014

#6 楼 @wangcityboy 好吧,忘记说我的是 iPad 了。。。
duration 参数 Python 也有,默认为 None,我用的默认值

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)
        """

#7 楼 @link1220
我这里问题以前就问过好几天了,论坛里面管理员都不回答,估计是没办法了吧。

匿名 #9 · September 12, 2014

#8 楼 @wangcityboy 从你的坐标值来看,你这应该执行的是向上拉而不是下拉吧 😬

#9 楼 @link1220 后来我改过了坐标,还是不行,不管上拉还是下拉。

匿名 #11 · September 12, 2014

#10 楼 @wangcityboy 那我就母鸡了。。。Java 不熟,没办法啦 🚶

#11 楼 @link1220 或许跟 ios 7.x 的版本有关吧,暂时不知道,不过谢谢你,你说了这么多。

匿名 #13 · September 12, 2014

#12 楼 @wangcityboy 😬 我的是 7.1.2

#13 楼 @link1220 你那能下拉刷新 tableView 么?

匿名 #15 · September 12, 2014

#14 楼 @wangcityboy 我没有这种环境的应用啊,我自己不会写。。

#15 楼 @link1220 嗯嗯,估计你那代码时实现滚动,没有下拉刷新的作用。

#8 楼 @wangcityboy 论坛管理员又不是专门回答问题的… 大家交流,互帮互助。其他人回答你也一样啊

#17 楼 @lihuazhang 你说的我知道,但这个问题比较棘手,还望前辈指教,不甚感激。

需要 Sign In 后方可回复, 如果你还没有账号请点击这里 Sign Up