Swipe/Scroll best practice with Java-Client 5

Yes, using latest stable build 5.0.4 as ochubey said. Trying this on a real Samsung S5 with 1080x1920 screen size— also same issue on Nexus 6. Also using Java JDK 8 and selenium 3.9.1. Testing on native android app.

The strange thing is it actually swiped ok one time, very very slowly (maybe over 10 seconds even though duration was set to 2 seconds). After that, it keeps erroring with subsequent runs, even with fresh restart of appium and clearing the app’s cache.

Should I submit appium bug report?

I’ve just tried this on the native Google Play Store app and it’s working as expected, so it could be an issue with the apk I am testing, as it is an older version.

Best
Vince

Thanks for clarifying, I prefer to use latest versions of client as it has quite a few bug fixes. Also it helps author to report any bugs found

Hi Vikram,

When i use the latest version of javaclient, i get the following error.

FAILED CONFIGURATION: @BeforeTest setCapabilities

java.lang.NoClassDefFoundError: org/apache/http/auth/Credentials

at com.contacts.BaseClass.setCapabilities(BaseClass.java:25)

i am using :
Selenium Version : 3.6.0

java client : 6.0.0-BETA4

TestNG :6.13.1

Appium : 1.7.2

This error is coming from the capabilities i have set in BaseClass, please find the Baseclass below :

esiredCapabilities caps = new DesiredCapabilities ();

caps.SetCapability(MobileCapabilityType.DeviceName, " ");

caps.SetCapability(MobileCapabilityType.PlatformVersion, " ");

caps.SetCapability(MobileCapabilityType.AppPackage, " ");

caps.SetCapability(MobileCapabilityType.AppActivity, " ");

We can use the following the code snippet to scroll down but please make sure you catch the exceptions.

try {
	driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(text(\"\"))");
}catch(Exception e) {
	System.out.println("whatever");
}

Hi,
I tried this for Image Carousel swipe and it worked.

public boolean swipeImages()
{
try
{
WebElement pageIndicator = driver.findElement(page_indicator);
String pageString= pageIndicator.getAttribute(“value”);
int length = pageString.length();
String count_string= pageString.substring(length-2, length);
int count = Integer.parseInt(count_string);
for (int i=1; i<=count; i++){

	  JavascriptExecutor js = (JavascriptExecutor) driver;
	  HashMap<String, String> scrollObject = new HashMap<String, String>();
	  scrollObject.put("direction", "right");
	  js.executeScript("mobile: scroll", scrollObject);
	  
		   }
		   System.out.println("Swipe Successfully");
		
	}
	catch (Exception e) 
	{
		System.out.println("Image Swipe was not successful.");
		
	}

Hi, i have used the below code to Swipe / Scroll and it is working perfectly.
Code to Swipe UP
public boolean swipeFromUpToBottom()
{
try {
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, String> scrollObject = new HashMap<String, String>();
scrollObject.put(“direction”, “up”);
js.executeScript(“mobile: scroll”, scrollObject);
System.out.println(“Swipe up was Successfully done.”);
}
catch (Exception e)
{
System.out.println(“swipe up was not successfull”);
}
return false;
}
Code to Swipe DOWN
public boolean swipeFromBottomToUp()
{
try {
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, String> scrollObject = new HashMap<String, String>();
scrollObject.put(“direction”, “down”);
js.executeScript(“mobile: scroll”, scrollObject);
System.out.println(“Swipe down was Successfully done”);
}
catch (Exception e)
{
System.out.println(“swipe down was not successfull”);
}
return false;
}

Thanks !!

@vinitaPatil This is not working in Scroll-able Popup Menu.Do You have any Idea How to Scroll In Popup ?

@VikramVI it’s make my day but i can’t understand Code new TouchAction(driver).press(115, 650).waitAction(ofSeconds(1)).moveTo(115, 350).release().perform(); In Press you have to passed (115,650) what does That mean ? And In Move to You have to Pass (115,350) What does that mean ? How to measure Co-ordinate I don’t Know. Can You Please explain How to Measure Co-ordinate in Mobile ?

What if the list of items have dynamic text, what would be the best to click on all the items of the list using UiSelector/UiScrollable?

Here is my code for scrolling up and down.
Dimension windowSize = androidElementAndroidDriver.manage().window().getSize();
Map<String, Object> args = new HashMap<String, Object>();
args.put(“command”, “am”);
args.put(“command”, “input”);
int yearNow = Calendar.getInstance().get(Calendar.YEAR);
if (yearNow < Integer.valueOf(year)) {
args.put(“args”, Lists.newArrayList(“swipe”, windowSize.width / 2, windowSize.height / 2, windowSize.width / 2, windowSize.height / 2));

        } else {
            args.put("args", Lists.newArrayList("swipe", windowSize.width / 2, windowSize.height / 2, windowSize.width / 2, windowSize.height));
        }