[英]How to swipe Horizontally in appium Android
I need to swipe a element from left to right.我需要从左向右滑动一个元素。 How to achieve it.
如何实现。
I tried:我试过:
new TouchAction(driver).press(214, 1219).moveTo(854,1199).release().perform();
But no luck.但没有运气。 Can any one help me to swipe this button from left to right?
谁能帮我从左向右滑动这个按钮?
Hard-coding the x and y locations is not the best idea, but if you want to swipe horizontally, the y points should be the same.硬编码 x 和 y 位置不是最好的主意,但如果你想水平滑动,y 点应该是相同的。 They're 20 pixels off in your example.
在您的示例中,它们相差 20 像素。 It probably does not affect the outcome, however.
然而,它可能不会影响结果。
Here's my method to swipe/scroll:这是我滑动/滚动的方法:
/**
* This method scrolls based upon the passed parameters
* @author Bill Hileman
* @param int startx - the starting x position
* @param int starty - the starting y position
* @param int endx - the ending x position
* @param int endy - the ending y position
*/
@SuppressWarnings("rawtypes")
public void scroll(int startx, int starty, int endx, int endy) {
TouchAction touchAction = new TouchAction(driver);
touchAction.longPress(PointOption.point(startx, starty))
.waitAction(WaitOptions.waitOptions(ofSeconds(1)))
.moveTo(PointOption.point(endx, endy))
.release()
.perform();
}
Now I then have other methods that use screen coordinates to determine what the x's and y's should be, and then call the scroll method, like this:现在我有其他方法使用屏幕坐标来确定 x 和 y 应该是什么,然后调用滚动方法,如下所示:
/**
* This method does a swipe right
* @author Bill Hileman
*/
public void swipeRight() {
//The viewing size of the device
Dimension size = driver.manage().window().getSize();
//Starting x location set to 5% of the width (near left)
int startx = (int) (size.width * 0.05);
//Ending x location set to 95% of the width (near right)
int endx = (int) (size.width * 0.95);
//y position set to mid-screen vertically
int starty = size.height / 2;
scroll(startx, starty, endx, starty);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.