Search code examples
androidautomated-testsappiumseekbarandroid-seekbar

Can't move Android SeekBar with Appium


I have a customized Android seekbar like this, and the positions where it can move to. And it starts from the middle:

enter image description here

I want to move the slider first and then check if it's saved. I have a method which I use 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();
}

Something I notice that:

  • seekbar doesn't move at all
  • getX and getY are always the same values even I tried to set slider back to very left before I call this method

I tried with sendkeys like this:

seekbar.sendKeys("0.5");

and it worked: it moved the slider to the very left, and it only worked with 0.5, when I entered a number within the range from 0 to 1, it didn't work

Any help much appreciated. Thanks


Solution

  • I just solved my problem: instead of using press(), I try longpress() and it works like a charm! I can move seekbar where I want.