问题描述
我有一个Android视频播放器库的SeekBar
,我想使用硒将其向前/向后移动:
I have a SeekBar
of an Android video player library, and I want to move it using selenium in forward/backward direction:
我想将此SeekBar
向前/向后移动,但是我无法做到这一点.我正在尝试以以下方式前进:
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();
但是无论我是否更改end
和start
的值,总是会遇到某个问题.我尝试向后移动的代码为:
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.
推荐答案
您可以尝试第二种解决方案,但长按而不是按
Could you try the second solution but use there long-press instead of the press
action.longpress(start, y).moveTo(moveTo, y).release().perform();
这篇关于如何在硒中向前/向后移动Android Seekbar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!