无法通过Appium移动Android SeekBar [英] Can't move Android SeekBar with Appium
问题描述
我有一个像这样的自定义Android搜寻栏,以及它可以移动到的位置.它从中间开始:
I have a customized Android seekbar like this, and the positions where it can move to. And it starts from the middle:
我想先移动滑块,然后检查它是否已保存.我有一种使用TouchAction的方法:
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();
}
我注意到:
- 搜索栏完全不动
- getX和getY始终是相同的值,即使在尝试调用此方法之前我尝试将滑块设置回最左侧
我尝试过这样的sendkey:
I tried with sendkeys like this:
seekbar.sendKeys("0.5");
并起作用:将滑块移到最左侧,并且仅在0.5时起作用,当我输入0到1范围内的数字时,它不起作用
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
推荐答案
我刚刚解决了我的问题:我尝试使用longpress()而不是使用press(),它的工作原理很吸引人!我可以将搜索栏移到想要的位置.
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.
这篇关于无法通过Appium移动Android SeekBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!