我无法使用Java在Appium中为我做滑动手势 [英] I can't make swipe gesture work for me in Appium using Java

查看:179
本文介绍了我无法使用Java在Appium中为我做滑动手势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法执行滑动"操作.我确实在网络上浏览了几天,发现了许多类似的问题,但是没有有效的答案.我也尝试过TouchAction类,效果也不佳.

I can't made Swipe action work. I did browsed through the web for a few days and found many similar questions but there is no working answer. Also I have tried TouchAction class, doesn't work as well.

我有Appium版本1.4.13(Draco),并使用Java,TestNG框架.

I have Appium Version 1.4.13 (Draco) and using Java, TestNG framework.

顺便说一句,我使用了滚动功能(可以使用与拉动相同的逻辑来刷新),这里是代码示例.

btw I made scrolling work using (you can use the same logic as a pull to refresh) here is code sample.

public void scrollUp() {
    JavascriptExecutor js = (JavascriptExecutor) getDriver();
    HashMap<String, String> scrollObject = new HashMap<String,String();
    scrollObject.put("direction", "up");
    scrollObject.put("element", listElements.get(1).getText());
    js.executeScript("mobile: scroll", scrollObject);
}

推荐答案

driver.context("NATIVE_APP"); 
        Dimension size = driver.manage().window().getSize(); 
        int startx = (int) (size.width * 0.8); 
        int endx = (int) (size.width * 0.20); 
        int starty = size.height / 2; 
        driver.swipe(startx, starty, endx, starty, 1000);

使用上面的代码.如果您想以相反的方向滑动,请将startx更改为starty.

Use above code. Change startx to starty if you wish to swipe in opposite direction.

这篇关于我无法使用Java在Appium中为我做滑动手势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆