如何在android for appium中执行垂直滑动

2023-12-14

我在真实设备上使用 Appium 1.7 和 Android 8。但我坚持向上滑动。尝试不同的组合。您能否提供一个简单的滑动功能代码?

Tried:

private void scrollDown() {
    //if pressX was zero it didn't work for me
    int pressX = driver.manage().window().getSize().width / 2;
    // 4/5 of the screen as the bottom finger-press point
    int bottomY = driver.manage().window().getSize().height * 4/5;
    // just non zero point, as it didn't scroll to zero normally
    int topY = driver.manage().window().getSize().height / 8;
    //scroll with TouchAction by itself
    scroll(pressX, bottomY, pressX, topY);
}

/*
 * don't forget that it's "natural scroll" where 
 * fromY is the point where you press the and toY where you release it
 */
private void scroll(int fromX, int fromY, int toX, int toY) {
    TouchAction touchAction = new TouchAction(driver);
    touchAction.longPress(fromX, fromY).moveTo(toX, toY).release().perform();
}

但没有运气..!!


private void scroll(int fromX, int fromY, int toX, int toY) {
   TouchAction touchAction = new TouchAction(driver);
   touchAction.tap(fromX, fromY).waitAction(1000).moveTo(toX, 
   toY).release().perform();
}

按下后必须等待。 这会起作用 可以使用它从 a 点向任意方向滑动到 b 点

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在android for appium中执行垂直滑动 的相关文章

随机推荐