[英]Appium iOS swipe is clicking
嘗試在應用程序中滑動對話(以將其刪除),但Appium充當單擊。 我在兩個設備上嘗試了此方法,這些設備的開始和結束位置以及持續時間具有不同的變量。 這是代碼:
driver.swipe(250,240,0,240,300);
有沒有人看到過同樣的問題,如果是的話,您的解決方案是什么?
我嘗試了帶有press-wait-moveTo-release
和longPress longPress-moveTo-release
動作的TouchAction,但是結果相同。 而且,我可以告訴我可以無問題地上下滾動,但是從左到右,反之亦然似乎不起作用。
一些其他信息:
我使用此代碼及其向我證明的自身。 它適用於iOS和Android。
它可能被認為已被棄用,但對我來說卻可行,並且我沒有找到更好的解決方案。
public static void swipe(MobileDriver driver, DIRECTION direction, long duration) {
Dimension size = driver.manage().window().getSize();
int startX = 0;
int endX = 0;
int startY = 0;
int endY = 0;
switch (direction){
case RIGHT:
startY = (int) (size.height /2);
startX = (int) (size.width * 0.90);
endX = (int) (size.width * 0.05);
break;
case LEFT:
startY = (int) (size.height /2);
startX = (int) (size.width * 0.05);
endX = (int) (size.width * 0.90);
break;
case UP:
endY= (int) (size.height * 0.70);
startY = (int) (size.height * 0.30);
startX = (size.width / 2);
break;
case DOWN:
startY = (int) (size.height * 0.70);
endY = (int) (size.height * 0.30);
startX = (size.width / 2);
break;
}
new TouchAction(driver)
.press(startX, startY)
.waitAction(Duration.ofMillis(duration))
.moveTo(endX, startY)
.release()
.perform();
}
DIRECTION
只是一個枚舉,其值為UP, DOWN...
實現方法可能看起來像這樣
public void swipeScreen(String direction) {
JavascriptExecutor js = Device.driver;
HashMap<String, String> scrollObject = new HashMap<>();
scrollObject.put("direction", direction);
js.executeScript("mobile: scroll", scrollObject);
}
然后使用 ( 不要忘了先聲明String ) 調用上述方法
String DOWN="down";
String LEFT ="left";
swipeScreen(DOWN); //or swipeScreen(LEFT); ....likewise up and Right
官方網站上的最佳參考
嘗試這個:
Thread.sleep(3000);
new TouchAction(driver)
.press(PointOption.point(500, 596))
.waitAction(WaitOptions.waitOptions(Duration.ofMillis(1000)))
.moveTo( PointOption.point(518, 478))
.release()
.perform();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.