How to scroll up and down on iOS app

#1

How to scroll up and down on iOS app.

I have a registration form, the fields which are towards bottom of the page are not visible. How to scroll down and also how to scroll up

0 Likes

#2

Try using driver.scrollTo(“String”); or use swipe functionality:

public static void TopToBottonSwipe(AppiumDriver driver) throws InterruptedException {
// Get the size of screen.
size = driver.manage().window().getSize();
System.out.println(size);

  // Find swipe start and end point from screen's with and height.
  // Find startx point which is at right side of screen.
  int starty = (int) (size.width * 0.90);
  // Find endx point which is at left side of screen.
  int endx = (int) (size.width * 0.20);
  // Find vertical point where you wants to swipe. It is in middle of
  // screen height.
  int startx = size.width / 2;
  // Swipe from Left to Right.
  driver.swipe(endx, starty, startx, starty, 1000);
  Thread.sleep(2000);

}

0 Likes

#3

I tired using scroll to, got an error : The method scrollTo(SeeTestIOSElement) is undefined for the type SeeTestIOSDriver:

0 Likes

#4

This works for me in iOS app:
driver.swipe(SwipeElementDirection.DOWN, 100, 500);
driver.swipe(SwipeElementDirection.UP, 100, 500);

You can change offset and time as per your requirement.

0 Likes

#5

The Swipe Up and down works fine, however when the focus is inside the text control, swipe down is not working.
Here is the code.

			driver.findElementByXPath("//*[@placeholder='PHONE NUMBER']").click();
			driver.findElementByXPath("//*[@placeholder='PHONE NUMBER']").sendKeys("9880788000");
			
			//driver.findElementByName("*").isDisplayed();
			driver.findElementByXPath("((//*/*[@class='UIAView'])[8]/*/*[@class='UIAStaticText'])[8]").click();
			
			driver.swipe(SwipeElementDirection.DOWN, 250, 1515);
			Thread.sleep(1000);

I have email text control below the phone number, i am unable to scroll down from phone number to email after entering the phone number.(Without send key, i am able swipe down and up successfully). Any help here is highly appreciable.

0 Likes

#6

It’s not a good practice to swipe using pixels because when the screen size changes your function will be useless.
As I replied earlier:

size = driver.manage().window().getSize();

Then use height and width percentages, it will help you with the compatibility of your code.

2 Likes

#7

Hi,

I have around 10 text controls, how to swipe to the last one using the above function?
Where to pass the element? what are 0.90 and 0.20? Please explain? Can i use this has an abstract class(POM) and call from the main class.

Thanks

0 Likes

#8

@cheluvambika
The percentages works like, your device width is 100% and your device height is 100%. Now you want to start a swipe action from the half height of your screen to all the way to the bottom of the screen.
In this case:
The startx and end x does not matter as x is the horizontal map. So put startx and endx to half of the width (size.width/2).
Y is vertical mapping so Now for starty and endy, put starty to half of the screen as we have to start the swipe from half of the screen height so:
endy= size.height/2 or (size.height * 0.50) // [50 %]
starty = 0 // All the way to the bottom

now run the function
driver.swipe with the above values.

Also size is variable of data type - dimension

0 Likes

#9

Hi @Abhay

while using driver.swipe(SwipeElementDirection.DOWN, 100, 500); it showing that The method swipe(int, int, int, int, int) in the type AppiumDriver is not applicable for the arguments (SwipeElementDirection, int, int)

0 Likes

#10

Hi @cheluvambika

while using driver.swipe(SwipeElementDirection.DOWN, 100, 500); it showing that The method swipe(int, int, int, int, int) in the type AppiumDriver is not applicable for the arguments (SwipeElementDirection, int, int)
[/quote]

0 Likes

#11

this method is not supported in the standard appium driver.

I’d recommend you to upgrade to the 11.2 version and use swipe(int startX,int startY, int endX, int endY, int duration) method

http://d242m5chux1g9j.cloudfront.net/AppiumStudio_windows_11_2_32.exe

0 Likes

#12

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();

0 Likes