How to move Android Seekbar forward/backward in selenium

冷暖自知 提交于 2020-07-10 08:13:13

问题


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

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:


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

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


来源:https://stackoverflow.com/questions/62757776/how-to-move-android-seekbar-forward-backward-in-selenium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!