[英]Appium - Java, How to automate swipe in android?
嘗試使用appium自動化android應用時,輸入以下代碼以進行刷卡操作----
TouchAction io.appium.java_client.TouchAction.press(WebElement el)
@Deprecated
TouchAction ac = new TouchAction(driver);
ac.press(436,652).moveTo(-311,-14).release().perform();
什么可以用來刷卡?
不建議使用坐標或等待時間。 現在,您應該使用ActionOptions 。 對於點,它們稱為PointOptions 。
在為它提供開始和停止滑動的元素時,TouchAction對我有用:
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();
以下代碼中的waitAction
對於正確實現waitAction
至關重要(這花了我幾個小時的學習時間)。
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();
}
我認為評論者之一,邁克(Mike),關於過時的等待時間可能是正確的。 (所有源代碼都散亂了。)這是我使用的代碼。 希望能幫助到你。
new TouchAction(driver).longPress(PointOption.point(x, y)).moveTo(PointOption.point(x, y)).release().perform();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.