[英]Appium iOS swipe is clicking
In attempt to swipe a conversation (to delete it) in the application, but Appium acts as clicking. 尝试在应用程序中滑动对话(以将其删除),但Appium充当单击。 I tried it on two devices with different variables for start and end position as well as duration. 我在两个设备上尝试了此方法,这些设备的开始和结束位置以及持续时间具有不同的变量。 Here is the code: 这是代码:
driver.swipe(250,240,0,240,300);
Did anyone saw the same issue, if so, what was your solution? 有没有人看到过同样的问题,如果是的话,您的解决方案是什么?
I tried TouchActions with press-wait-moveTo-release
as well as longPress-moveTo-release
actions, but have the same result. 我尝试了带有press-wait-moveTo-release
和longPress longPress-moveTo-release
动作的TouchAction,但是结果相同。 More over, I can tell that I can scroll up and down without an issue, but left to right and vise versa don't seem to work. 而且,我可以告诉我可以无问题地上下滚动,但是从左到右,反之亦然似乎不起作用。
Some additional information: 一些其他信息:
I use this code and its proven itself to me. 我使用此代码及其向我证明的自身。 It works for both iOS and Android. 它适用于iOS和Android。
It might be considered as deprecated, but for me it works, and I did not find any better solution. 它可能被认为已被弃用,但对我来说却可行,并且我没有找到更好的解决方案。
public static void swipe(MobileDriver driver, DIRECTION direction, long duration) {
Dimension size = driver.manage().window().getSize();
int startX = 0;
int endX = 0;
int startY = 0;
int endY = 0;
switch (direction){
case RIGHT:
startY = (int) (size.height /2);
startX = (int) (size.width * 0.90);
endX = (int) (size.width * 0.05);
break;
case LEFT:
startY = (int) (size.height /2);
startX = (int) (size.width * 0.05);
endX = (int) (size.width * 0.90);
break;
case UP:
endY= (int) (size.height * 0.70);
startY = (int) (size.height * 0.30);
startX = (size.width / 2);
break;
case DOWN:
startY = (int) (size.height * 0.70);
endY = (int) (size.height * 0.30);
startX = (size.width / 2);
break;
}
new TouchAction(driver)
.press(startX, startY)
.waitAction(Duration.ofMillis(duration))
.moveTo(endX, startY)
.release()
.perform();
}
DIRECTION
is just an enum with values UP, DOWN...
DIRECTION
只是一个枚举,其值为UP, DOWN...
Implementation method may look like this 实现方法可能看起来像这样
public void swipeScreen(String direction) {
JavascriptExecutor js = Device.driver;
HashMap<String, String> scrollObject = new HashMap<>();
scrollObject.put("direction", direction);
js.executeScript("mobile: scroll", scrollObject);
}
Then call the above method using ( Don't forget to declare String first ) 然后使用 ( 不要忘了先声明String ) 调用上述方法
String DOWN="down";
String LEFT ="left";
swipeScreen(DOWN); //or swipeScreen(LEFT); ....likewise up and Right
Best reference at the official web 官方网站上的最佳参考
Try this: 尝试这个:
Thread.sleep(3000);
new TouchAction(driver)
.press(PointOption.point(500, 596))
.waitAction(WaitOptions.waitOptions(Duration.ofMillis(1000)))
.moveTo( PointOption.point(518, 478))
.release()
.perform();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.