gpt4 book ai didi

java - 如何使用 TouchAction 在 Appium 1.7.1 中滚动

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:44:57 26 4
gpt4 key购买 nike

我在向下滚动到 iOS 和 Android 应用程序中的某个元素时遇到问题。自从 Appium 1.6.3 更新到 1.7.1 以及 io.appium 更新到 6.1.0 以来,不推荐使用滑动方法,唯一的解决方案是使用 TouchActions。

我尝试用 TouchActions 解决它,但它根本没有滚动或滚动方向错误。

到目前为止,我的解决方案是这样的,也许有人可以解释我做错了什么:

public void scrollDownUntilElementVisible(WebElement element){
TouchAction touchAction = new TouchAction(getDriver());
for(int i=0; i<dimensions.getHeight();i++){
if(element.isDisplayed()){
break;
}else{
touchAction.press(0,0).moveTo(element).release().perform();
}
}
}

这不是完整的代码,但我希望您能理解。

如果我使用 x,y 坐标而不是我在示例中寻找的 webElement,它会如何工作?它不像以前版本的滑动方法那样工作,或者我没有做对。也许有人可以解释一下。

最佳答案

在最新版本的 Appium 上需要添加(PointOption.point 同时传递坐标)一些使用 TouchAction 滚动的代码:

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);
}



private void scroll(int fromX, int fromY, int toX, int toY) {
TouchAction touchAction = new TouchAction(driver);
touchAction.longPress(PointOption.point(fromX, fromY)).moveTo(PointOption.point(toX, toY)).release().perform();
}

关于java - 如何使用 TouchAction 在 Appium 1.7.1 中滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44282417/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com