在 Android 应用程序中使用 Appium 定位元素后,如何水平滑动? [英] How can i swipe horizontally after locating an element using Appium in an Android app?

查看:26
本文介绍了在 Android 应用程序中使用 Appium 定位元素后,如何水平滑动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用了以下代码,但它不起作用:

I have used the following code, but it is not working:

int startX = driver.findElement(By.xpath("//*[@class='android.widget.FrameLayout' and @index='1']")).getLocation.getX();
int startY = driver.findElement(By.xpath("//*[@class='android.widget.FrameLayout' and @index='1']")).getLocation.getY();

我得到的错误是:

getLocation cannot be resolved or is not a field

推荐答案

首先你应该尝试使用 getLocation() 代替:.getLocation.getY().

Firstly you should try getting location as getLocation()instead of: .getLocation.getY().

其次,您可以使用以下方法在所有方向上实现滑动/滚动:

Secondly you can implement swipe/scroll in all directions using:

TouchAction action = new TouchAction(driver);

        int startY = element1.getLocation().getY() + (element1.getSize().getHeight() / 2);
        int startX = element1.getLocation().getX() + (element1.getSize().getWidth() / 2);

        int endX = element2.getLocation().getX() + (element2.getSize().getWidth() / 2);
        int endY = element2.getLocation().getY() + (element2.getSize().getHeight() / 2);

        action.press(startX, startY).waitAction(2000).moveTo(endX, endY).release().perform();

这篇关于在 Android 应用程序中使用 Appium 定位元素后,如何水平滑动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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