How to move Android Seekbar forward/backward in selenium

Viewed 630

I have a SeekBar of an Android video player library, and I want to move it using selenium in forward/backward direction:

enter image description here

I want to move this SeekBar in forward/backward direction but I'm not able to do that. I am trying to move forward as:

 MobileElement seekBar = (MobileElement) driver.findElementByClassName("android.widget.SeekBar");
        seekBar.click();
// get start co-ordinate of seekbar
    int start = seekBar.getLocation().getX();
    // Get width of seekbar
    int end = seekBar.getSize().getWidth();
    // get location of seekbar vertically
    int y = seekBar.getLocation().getY();

    // Select till which position you want to move the seekbar
    TouchAction action = new TouchAction(driver);

    // Move it 40%
    int moveTo = (int) (end * 0.4);
    action.longPress(start, y).moveTo(moveTo, y).release().perform();

But its always coming to a certain point whether I change value for end and start or not. The code I'm trying to move backward is as:

public void moveSeekBarBackward(MobileElement seekBar, AndroidDriver<WebElement> driver) {
    // get start co-ordinate of seekbar
    seekBar.click();
    int start = seekBar.getLocation().getX();

    // Get width of seekbar
    int end = seekBar.getSize().getWidth();
    // get location of seekbar vertically
    int y = seekBar.getLocation().getY();

    // Select till which position you want to move the seekbar
    TouchAction action = new TouchAction(driver);

    // Move it 20%
    int moveTo = (int) (end * 0.2);
    action.longPress(start, y).moveTo(moveTo, y).release().perform();
}

Above code is starting the video from the same place where it starts after making it forward. Please let me know if you the correct solution for it.

1 Answers

Could you try the second solution but use there long-press instead of the press

action.longpress(start, y).moveTo(moveTo, y).release().perform();
Related