I have 5 swipe screens and my code just stuck at 3rd screen i want to scroll Horizontally.
Asked
Active
Viewed 3,335 times
0

Ahmed Ali QA Engineer
- 41
- 1
- 3
- 12
-
This is my screen dimensions App window dimensions -> (720, 1280) – Ahmed Ali QA Engineer May 24 '18 at 08:05
-
Where is your code? – Vikasdeep Singh May 24 '18 at 08:05
-
public static void swipe(){ Dimension size = driver.manage().window().getSize(); System.out.println("App window dimensions -> " + size); //swiping from right to left driver.swipe(size.width-1, size.height/2, 1, size.height/2, 200); } – Ahmed Ali QA Engineer May 24 '18 at 08:05
-
@AhmedAliQAEngineer [Edit] your code into your question. – khelwood May 24 '18 at 08:06
-
Put this code in your question body NOT here in comments – Vikasdeep Singh May 24 '18 at 08:06
-
i am unable to edit this question – Ahmed Ali QA Engineer May 24 '18 at 08:08
2 Answers
2
here is code that has proven good to me:
enum DIRECTION{UP, DOWN, LEFT, RIGHT};
and:
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();
}
Hope it helps...

Kovacic
- 1,473
- 6
- 21
1
Use below method for swiping horizontally:
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.ofMillis(duration)).moveTo(endPoint, anchor).release().perform();
}
Call the above method by:
swipeHorizontal((AppiumDriver) driver,0.9,0.01,0.5,2000);

Al Imran
- 882
- 7
- 29
-
-
-
`for(int i=0 ; i<=4;i++){ 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().moveTo(endPoint, anchor).release().perform(); }` – Ahmed Ali QA Engineer May 24 '18 at 08:36
-
-
Thread.sleep(3000); swipeHorizontal((AppiumDriver) driver,0.9,0.01,0.5,5000); – Ahmed Ali QA Engineer May 24 '18 at 08:36
-
`swipeHorizontal((AppiumDriver) driver,0.9,0.01,0.5,5000); Thread.sleep(3000); ` – Al Imran May 24 '18 at 08:39