无法使用Appium移动Android SeekBar

Rag*_*son 7 android automated-tests seekbar appium android-seekbar

我有一个这样的自定义Android搜索栏,以及它可以移动到的位置.它从中间开始:

在此输入图像描述

我想首先移动滑块,然后检查它是否已保存.我有一个使用TouchAction的方法:

public void moveSeekBar(){
    WebElement seekBar = appiumDriver.findElementById("com.feverapp:id/SymptomTrackingActivity_var");
    //Get start point of seekbar.
    int startX = seekBar.getLocation().getX();
    System.out.println(startX);
    //Get end point of seekbar.
    int endX = seekBar.getSize().getWidth();
    System.out.println(endX);
    //Get vertical location of seekbar.
    int yAxis = seekBar.getLocation().getY();
    //Set slidebar move to position.
    // this number is calculated based on (offset + 3/4width)
    int moveToXDirectionAt = 786;
    System.out.println("Moving seek bar at " + moveToXDirectionAt+" In X direction.");
    //Moving seekbar using TouchAction class.
    TouchAction act=new TouchAction(appiumDriver);
    act.press(startX,yAxis).moveTo(moveToXDirectionAt,yAxis).release().perform();
}
Run Code Online (Sandbox Code Playgroud)

我注意到的一点:

  • seekbar根本不动
  • getX和getY总是相同的值,即使我在调用此方法之前尝试将滑块设置回左侧

我尝试使用这样的sendkeys:

seekbar.sendKeys("0.5");
Run Code Online (Sandbox Code Playgroud)

并且它工作:它将滑块移动到最左边,它只用0.5,当我输入0到1范围内的数字时,它不起作用

任何帮助非常感谢.谢谢

Rag*_*son 1

我刚刚解决了我的问题:我没有使用 press(),而是尝试了 longpress(),它的效果就像一个魅力!我可以将搜索栏移动到我想要的位置。