问题
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