@akbar,从提供的经验示例中,您可以尝试一下吗
TouchAction ta = new TouchAction(driver);
ta.press(434, 468).waitAction(Duration.ofMillis(1000)).moveTo(471, 312).release().perform();
=====================================
或者(方法#2)
考虑这个例子
public static void swipeHorizontal(AppiumDriver driver, double startPercentage, double finalPercentage, double anchorPercentage, int duration) throws Exception {
Dimension size = driver.manage().window().getSize();
int anchor = (int) (size.height * anchorPercentage);
int startPoint = (int) (size.width * startPercentage);
int endPoint = (int) (size.width * finalPercentage);
new TouchAction(driver).press(startPoint, anchor)
.waitAction(duration)
.moveTo(endPoint, anchor)
.release()
.perform();
//In documentation they mention moveTo coordinates are relative to initial ones, but thats not happening. When it does we need to use the function below
//new TouchAction(driver).press(startPoint, anchor).waitAction(duration).moveTo(endPoint-startPoint,0).release().perform();
}
并用您的主题中的值调用它是:
swipeHorizontal(driver,0.9,0.01,0.5,3000);
注意关于绝对/相对值的注释
====================================
还有另一种方法(方法#3)
看看这个线程
Appium 版本 1.9.1 和客户端升级到 7.0.0刷卡使用以下代码(垂直刷卡。用于水平刷卡 - 从 'dimensions' 更改getHeight()
)getWidth()
:
TouchAction action = new TouchAction(driver);
PointOption p1= new PointOption();
Dimension dimensions = driver.manage().window().getSize();
Double screenHeightStart = dimensions.getHeight() * 0.5;
int h1 = screenHeightStart.intValue();
Double screenHeightEnd = dimensions.getHeight() * 0.2;
int h2 = screenHeightEnd.intValue();
action.press(PointOption.point(0,h1))
.waitAction(new WaitOptions().withDuration(Duration.ofMillis(600)))
.moveTo(PointOption.point(0, h2))
.release()
.perform();
这对我来说非常有效。希望这可以帮助,
最好的问候,尤金