Appium - Java, How to automate swipe in android?

回眸只為那壹抹淺笑 提交于 2020-01-02 23:14:17

问题


Trying to automate android app using appium, when entered the below code for swipe giving ----

TouchAction io.appium.java_client.TouchAction.press(WebElement el) 
@Deprecated
TouchAction ac = new TouchAction(driver);
ac.press(436,652).moveTo(-311,-14).release().perform();

What can be used to swipe?


回答1:


The use of coordinates or wait times has been deprecated. You're now supposed to use ActionOptions. In the case of points, they're called PointOptions.




回答2:


TouchAction works for me when giving it elements to start and stop the swiping at:

WebElement start = driver.findElement(By.id("xxxxxx"));
WebElement stop = driver.findElement(By.xpath("xxxxxx"));
TouchAction action = new TouchAction(driver);
action.longPress(start).moveTo(stop).release().perform();



回答3:


The waitAction in the following code is crucial to properly implementing a swipe (that took me a couple hours of investigation to learn).

public static void actionSwipeLeft(AndroidDriver driver)
{
    Dimension dims = driver.manage().window().getSize();
    int       x    = (int) (dims.getWidth() * .5);
    int       y    = (int) (dims.getHeight() * .8);

    int       endX = 0;

    System.out.println("Swiping left.");

    new TouchAction(driver)
            .press(new PointOption().withCoordinates(x, y))
            .waitAction(new WaitOptions().withDuration(Duration.ofMillis(500)))
            .moveTo(new PointOption().withCoordinates(endX, y))
            .release()
            .perform();
}



回答4:


I think one of commentors, Mike, might be right about wait times being deprecated. (The sources are all discombobulated.) This is the code that I use. Hope it helps.

new TouchAction(driver).longPress(PointOption.point(x, y)).moveTo(PointOption.point(x, y)).release().perform();


来源:https://stackoverflow.com/questions/47730334/appium-java-how-to-automate-swipe-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!