This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.
1 / 12
Oct 2017

package te;

import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class lanuch {

AppiumDriver d;


	 @SuppressWarnings("rawtypes")
	public void appLaunch() throws MalformedURLException {
	  DesiredCapabilities cap = new DesiredCapabilities();

	  
	  
	  cap.setCapability(CapabilityType.BROWSER_NAME, "");

	  cap.setCapability("deviceName", "T5511");

	  cap.setCapability("platformName", "Android");

	  cap.setCapability(CapabilityType.VERSION, "6.0.1");

	  cap.setCapability("platformVersion", "7.1.2");

	  cap.setCapability("appPackage", "com.smartron.tband");
	  cap.setCapability("appActivity", "com.smartron.sid.ui.setupflow.SetupFlowWelcomeScreen");

	  d = new AndroidDriver(new URL("http://127.0.0.1:4710/wd/hub"), cap);
	  System.out.println("connected");

	  d.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
	  d.manage().window().getSize();
	  
	 }
	
	public void scroll() throws InterruptedException
	{
		Dimension dimensions = d.manage().window().getSize();
		
		for(int i=1; i>4; i++)
		{
			Double screenHeightStart = dimensions.getHeight() * 0.5;

			int scrollStart = screenHeightStart.intValue();

			Double screenHeightEnd = dimensions.getHeight() * 0.2;

			int scrollEnd = screenHeightEnd.intValue();

			d.swipe(0, scrollStart, 0, scrollEnd, 2000);

			
		}

}
public static void main(String args[]) throws MalformedURLException{
lanuch f=new lanuch();
f.appLaunch();
}

}

all code is correct d.swipe …unable to call the method

  • created

    Oct '17
  • last reply

    Jul '18
  • 11

    replies

  • 12.0k

    views

  • 10

    users

  • 2

    links

This method is deprecated from java client. You can use TouchAction class to swipe

new TouchAction(driver).press(startx, starty).waitAction(duration).moveTo(endx, endy).release().perform();

4 months later

I think the above swipe command is using absolute coordinates. Appium is now moved to the relative coordinate system.

you can use below code if needed,

TouchAction action = new TouchAction(driver);
action.press(startX, startY).moveTo((endX - startX), (endY-startY)).release().perform();

If someone doesn’t want to swipe through TouchAction then there is another method too. Find scrollable element thru AndroidUIAutomator and scroll till the text of the element.

25 days later

You can Try this and let me know if it’s help you

Dimension size=driver.manage().window().getSize();
	int width=(int)(size.width/2);
	int startPoint=(int)(size.getHeight() * 0.70);
	int endPoint=(int)(size.getHeight() * 0.20);
	int duration=2000;
	mobileDriver.swipe(width, startPoint, width, endPoint, duration);

Thank you.

1 month later

It is work with using PointerOption class.

TouchAction action = new TouchAction(d);
PointOption p1= new PointOption();
Dimension dimensions = d.manage().window().getSize();
Double screenHeightStart = dimensions.getHeight() * 0.5;
int h1 = screenHeightStart.intValue();
Double screenHeightEnd = dimensions.getHeight() * 0.2;
int h2 = screenHeightEnd.intValue();
action.press(p1.point(0, h1)).moveTo(p1.point(0,-h2)).release().perform();

1 month later

Hi,

Is this for swiping from left to right on mobile screen?

Since I’m currently trying
driver.swipe(780, 1400, -26, 1286, 682);

20 days later

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;
}
Code for carousel images swipe

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).trim();
int count = Integer.parseInt(count_string);
System.out.println("Number of Image available to Swipe: "+count);
for (int i=0; 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 successfull”);
}
return false;
}