簡體   English   中英

如何在appium Android中水平滑動

[英]How to swipe Horizontally in appium Android

我需要從左向右滑動一個元素。 如何實現。

元素截圖

我試過:

new TouchAction(driver).press(214, 1219).moveTo(854,1199).release().perform();

但沒有運氣。 誰能幫我從左向右滑動這個按鈕?

硬編碼 x 和 y 位置不是最好的主意,但如果你想水平滑動,y 點應該是相同的。 在您的示例中,它們相差 20 像素。 然而,它可能不會影響結果。

這是我滑動/滾動的方法:

/**
 * This method scrolls based upon the passed parameters
 * @author Bill Hileman
 * @param int startx - the starting x position
 * @param int starty - the starting y position
 * @param int endx - the ending x position
 * @param int endy - the ending y position
 */
@SuppressWarnings("rawtypes")
public void scroll(int startx, int starty, int endx, int endy) {

    TouchAction touchAction = new TouchAction(driver);

    touchAction.longPress(PointOption.point(startx, starty))
               .waitAction(WaitOptions.waitOptions(ofSeconds(1)))
               .moveTo(PointOption.point(endx, endy))
               .release()
               .perform();

}

現在我有其他方法使用屏幕坐標來確定 x 和 y 應該是什么,然后調用滾動方法,如下所示:

/**
 * This method does a swipe right
 * @author Bill Hileman
 */
public void swipeRight() {

    //The viewing size of the device
    Dimension size = driver.manage().window().getSize();

    //Starting x location set to 5% of the width (near left)
    int startx = (int) (size.width * 0.05);
    //Ending x location set to 95% of the width (near right)
    int endx = (int) (size.width * 0.95);
    //y position set to mid-screen vertically
    int starty = size.height / 2;

    scroll(startx, starty, endx, starty);

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM