java - 如何在 Android appium 中水平滑动

标签 java android appium

我需要从左向右滑动一个元素。如何实现。

Element screenshot

我尝试过:

new TouchAction(driver).press(214, 1219).moveTo(854,1199).release().perform();

但运气不佳。谁能帮我从左向右滑动这个按钮?

最佳答案

对 x 和 y 位置进行硬编码并不是最好的主意,但如果您想水平滑动,则 y 点应该相同。在您的示例中,它们相差 20 像素。不过,它可能不会影响结果。

这是我的滑动/滚动方法:

/**
 * This method scrolls based upon the passed parameters
 * @author Bill Hileman
 * @param int startx - the starting x position
 * @param int starty - the starting y position
 * @param int endx - the ending x position
 * @param int endy - the ending y position
 */
@SuppressWarnings("rawtypes")
public void scroll(int startx, int starty, int endx, int endy) {

    TouchAction touchAction = new TouchAction(driver);

    touchAction.longPress(PointOption.point(startx, starty))
               .waitAction(WaitOptions.waitOptions(ofSeconds(1)))
               .moveTo(PointOption.point(endx, endy))
               .release()
               .perform();

}

现在我有其他方法使用屏幕坐标来确定 x 和 y 应该是什么,然后调用滚动方法,如下所示:

/**
 * This method does a swipe right
 * @author Bill Hileman
 */
public void swipeRight() {

    //The viewing size of the device
    Dimension size = driver.manage().window().getSize();

    //Starting x location set to 5% of the width (near left)
    int startx = (int) (size.width * 0.05);
    //Ending x location set to 95% of the width (near right)
    int endx = (int) (size.width * 0.95);
    //y position set to mid-screen vertically
    int starty = size.height / 2;

    scroll(startx, starty, endx, starty);

}

关于java - 如何在 Android appium 中水平滑动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55183399/

相关文章:

java - 为什么我们在 Java 中实例化 Calendar Class(abstract)

java - 如何获取 hideSoftInputFromInputMethod(token, flags) 所需的 token ?

java - Java 中类实现文档注释的正确位置

android - java.lang.ClassCastException : android. support.v4.app.NoSaveStateFrameLayout 无法转换为 com.google.android.maps.MapView

java - 我如何在appium中选择时间

java - UIautomatorviewer Java 主页问题

java - Bitmap.Config.HARDWARE 与 Bitmap.Config.RGB_565

android - 在 Android 中四舍五入到小数点后两位

安卓 : Changing the color of ExpandableListView's group indicator

appium - 在 appium 医生中出现意外的 token 错误