如何在android中执行垂直滑动以获取appium [英] how to perform vertical swipe in android for appium
本文介绍了如何在android中执行垂直滑动以获取appium的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在真实设备上使用Appium 1.7和Android 8.但是我被卡住了.尝试了不同的组合.您能为滑动功能提供简单的代码吗?
I am using Appium 1.7 and Android 8 on real device. But I am stuck with swipe up. tried with different combinations. Could you please provide an easy code for swipe functionality?
尝试:
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();
}
但是没有运气.. !!
But no luck..!!
推荐答案
这为我提供了解决方案:
This gives me the solution:
TouchAction action = new TouchAction(driver);
action.longPress(bottomElement).moveTo(topElement).release().perform();
这篇关于如何在android中执行垂直滑动以获取appium的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文