how to scrollTo and swipe with java client 3.2.0 and appium 1.4.13 ?
Hi RGIAPN
There are APIs available in appium java client . you can use these APIs.
// For Scroll
driver.scroll(String);
driver.scrollToExact(String);
// for Swipe
driver.swipe(int fingers, WebElement, duration);
driver.swipe(int fingers, int x, int y, duration);
Hope this will help.
I tried all this methods, and none of these methods works
could you please share the piece of code which you are using for scroll and swipe?
private IOSDriver<WebElement> driver;
private ScreenRecorder screenRecorder;
@Test
public void f() {
}
@BeforeMethod
public void setUp() throws Exception {
// set up appium
// JSONObject obj = new JSONObject(" … ");
// String pageName = obj.getJSONObject(“pageInfo”).getString(“pageName”);
//
// JSONArray arr = obj.getJSONArray(“posts”);
// for (int i = 0; i < arr.length(); i++)
// {
// String post_id = arr.getJSONObject(i).getString(“post_id”);
// }
DesiredCapabilities capabilities = new DesiredCapabilities();
//real device
// capabilities.setCapability(“deviceName”, “iPad”);
// capabilities.setCapability(“udid”,“c0ff732e91bae98e61a11ce056dd727f30f5a2ae”);
// capabilities.setCapability(“bundleid”, “com.anghami.anghami”);
// capabilities.setCapability(“ipa”, “/Users/MacBookair2014/Desktop/Anghami.ipa”);
//simulator
capabilities.setCapability("platformName", "iOS");
capabilities.setCapability("platformVersion", "8.4");
capabilities.setCapability("deviceName", "iPhone 5");
capabilities.setCapability("app", "/Users/MacBookair2014/Desktop/Anghami.app");
driver = new IOSDriver<WebElement>(new URL("http://0.0.0.0:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
JavascriptExecutor js = (JavascriptExecutor)driver;
startRecording();
driver.findElement(By.name("Let's start!")).click();
driver.findElement(By.name("Email Login")).click();
// System.out.println(driver.findElementByIosUIAutomation(“applications()[1].windows()[1].textFields()[1]”).getAttribute(“value”));
driver.findElementByXPath("//UIAApplication[1]/UIAWindow[1]/UIATextField[1]").sendKeys("[email protected]");
driver.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIASecureTextField[1]")).sendKeys(“royanghami”);
driver.findElement(By.name(“Login”)).click();
// if(driver.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIAButton[8]")) != null)
// {
// driver.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIAButton[8]")).click();
// }
Thread.sleep(15000);
// js.executeScript(“mobile: scrollTo”, new HashMap<String, String>() {{ put(“element”, driver.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIATableView[2]/UIATableCell[5]")).getId()); }});
// driver.findElement(By.name(“Menu Menu”)).click();
// driver.findElement(By.xpath("//UIAApplication[1]/UIAWindow[1]/UIATableView[1]/UIATableCell[5]")).click();
//not functional on sim and real
// HashMap<String, String> scrollObject = new HashMap<String, String>();
// scrollObject.put(“direction”, “down”);
// js.executeScript(“mobile: scroll”, scrollObject);
//not functional on sim and real
driver.swipe(100,500,100,100,900);
//not functional on sim and real
// HashMap <String, Integer> swipeObject = new HashMap <String, Integer>();
// swipeObject.put(“startX”, 172);
// swipeObject.put(“startY”, 502);
// swipeObject.put(“endX”, 172);
// swipeObject.put(“endY”, 170);
// swipeObject.put(“duration”, 2000);
// js.executeScript(“mobile: swipe”, swipeObject);
//not functional on sim and real
// HashMap<String, String> swipeObject = new HashMap<String, String>();
// swipeObject.put(“element”, “Editors’ Choice”);
// js.executeScript(“mobile: scrollTo”, swipeObject);
driver.scrollTo("Editors' Choice");
stopRecording();
driver.close();
System.out.println("App launched");
Swipe is broken in simulators. Check around forum too see some solutions that users have tried.
In real device you should be able to swipe without any problem.
i tried in real device (iPad mini) and swipe doesn’t work, also scrollTo doesn’t work
reply with the swipe code that works on real device
The signature for AppiumDriver swipe is:
public void swipe(int startx, int starty, int endx, int endy, int duration)
You can try directly with TouchAction also or use swipe method in MobileElement.java. Go to https://github.com/appium/java-client/ and search for the terms you want.
Finally you also have selenium swipe.
@Telmo_Cardoso Swipe gesture is not broken anymore in simulator with Xcode 7. It works perfectly on my machine
Can anyone share the document for Appium Touch Action class??.
Hi Kishore
Here is the JAVA API documentation for Appium TouchAction class.
http://appium.github.io/java-client/
Thanks
Ravi
hi i am unable call.
driver.Swipe(); method …please help me on this
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);
}
}
unable use swipe method
swipe method was deprecated and now removed from latests java_client versions.
Please search on this forum for alternatives with TouchAction class
can u share me a code to swipe downnn
along with jars wats need’s to install
may i know which older version it will works