If someone has figured it out please share.
I’ve searching all over the net.
If someone has figured it out please share.
I’ve searching all over the net.
TouchAction ta = new TouchAction(d); //create object
ta.press(startx, starty).waitAction(dur).moveTo(endx, endy).release(); //press, wait, moveTo, release
ta.perform(); //actually performs the action.
you can use some code such as this for directions, and to get the x/y coordinates of an element.
int endx = 0;
int endy = 0;
int width = getAppWidth(d);
int height = getAppHeight(d);
Duration dur = Duration.ofSeconds(duration);
switch (direction) {
case UP:
endx = 0;
int toY = height - starty;
endy = (toY - starty) * swipeFactor;
break;
case RIGHT:
endx = (width - startx) * swipeFactor;
endy = 0;
break;
case DOWN:
endx = 0;
endy = (height - starty) * swipeFactor;
break;
case LEFT:
int toX = width - startx;
endx = (toX - startx) * swipeFactor;
endy = 0;
break;
}
OR if you have an element named item…
int x = item.getLocation().getX();
int y = item.getLocation().getY();
int w = item.getSize().getWidth();
int h = item.getSize().getHeight();
int tenthX = (w / 10); // Add X after calculation
int tenthY = (h / 10); // Add Y after calculation
int centerX = tenthX * 5 + x;
int centerY = tenthY * 5 + y;
// The parts we’re going to figure out
int startX = centerX;
int startY = centerY;
int endX = centerX;
int endY = centerY;
switch (direction) {
case UP:
startX = centerX;
startY = (tenthY * 8) + y;
endX = centerX;
endY = tenthY + y;
break;
case RIGHT:
startX = tenthX + x;
startY = centerY;
endX = (tenthX * 8) + x;
endY = centerY;
break;
case DOWN:
startX = centerX;
startY = tenthY + y;
endX = centerX;
endY = (tenthY * 8) + y;
break;
case LEFT:
startX = (tenthX * 8) + x;
startY = centerY;
endX = tenthX + x;
endY = centerY;
break;
Thank you very much for the fast and detailed response.
However, it doesn’t seem to work for me.
I am facing a strange behavior.
If I run the following code :
new TouchAction(driver).press(300,75).moveTo(0,-50).release().perform()
Then It swipes up (as expected).
But then, if I run the following code (with the minor changes):
new TouchAction(driver).press(300,75).moveTo(-50,0).release().perform()
It just clicks on the object in (300,75) and won’t swipe.
Any ideas?
Thanks.
Sigh, I’m actually getting the same bugs as well. Swiping left and right doesn’t seem to work.
@jlipps Hi,
Do you guys have any solution for it?
Are you in iOS? If yes, then place the duration to 0.
new TouchAction(driver).press( , ).waitAction(Duration.ofMillis(0)).moveTo( , ).release().perform();
I am on iOS.
Tried your suggestion but it still won’t work.
Are you sure about the java-client version?
TouchAction touchAction = new TouchAction(getDriver());
size = getDriver().manage().window().getSize();
System.out.println(size);
int startx = (int) (size.width * 0.5);
int endx =(int) (size.width * 0.2);
int starty = (int)(size.height0.8);
int endy = (int)(size.height0.2);
getDriver().swipe(startx, starty, startx, endy, 250);
This i used for swiping pages of a ebook
Hi , which java-client are you using ? 5?
@Kishore_v
Did you used it with java-client 5.0.3 ?
If so, what driver do you use?
I am using java client 3.2.0
appium version 1.7.1
used iOS driver, it swipes from right to left… testtes with iOS 11, in iphone 6s plus
My question regarded java-client 5.0.3.
Thanks.
You can still use swipe with 5.0.3.
According to the github changelog they deprecated appiumdriver #swipe and mobileElement#swipe. They did not deprecate iOSDriver #swipe.
So tldr you can use swipe as before if you use iOSDriver, which is the driver you should use unless I have missed something
They did deprecate it on IOSDriver, unfortunately.
@Aleksei
Do you have any clue about it?
Please show the code you are running and what happens (it clicks on the element instead of swiping?)
If I run the following code :
new TouchAction(driver).press(300,75).moveTo(0,-50).release().perform()
Then It swipes up (as expected).
But then, if I run the following code (with the minor changes):
new TouchAction(driver).press(300,75).moveTo(-50,0).release().perform()
It just clicks on the object in (300,75) and won’t swipe.
have you tried?
new TouchAction(driver).press(300,75).waitAction(Duration.ofMillis(0)).moveTo(-50,0).release().perform()
you can try this as well it should works as expected :
new TouchAction(item.initTest.Driver).press((int)(size.width / 13), (int) (size.height * 0.60)).waitAction(Duration.ofMillis(4000)).moveTo((int)(size.width / 13),(int) (size.height * (-0.30))).release().perform();
This code work to me :
Thread.sleep(3000);
new TouchAction(driver).press(PointOption.point(500, 596)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(1000))).
moveTo(PointOption.point(518, 478)).release().perform();