我有一个像这样的定制Android搜索栏,以及它可以移动到的位置。它从中间开始:
我想先移动滑块,然后检查它是否已保存。我有一个使用 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 始终是相同的值,即使我在调用此方法之前尝试将滑块设置回最左边
我尝试使用这样的发送键:
seekbar.sendKeys("0.5");
它起作用了:它将滑块移到了最左边,并且仅适用于 0.5,当我输入 0 到 1 范围内的数字时,它不起作用
非常感谢任何帮助。谢谢
@Test
public void testSeekBar()throws Exception
{
//Locating seekbar using resource id
WebElement seek_bar=driver.findElement(By.id("seek_bar"));
// get start co-ordinate of seekbar
int start=seek_bar.getLocation().getX();
//Get width of seekbar
int end=seek_bar.getSize().getWidth();
//get location of seekbar vertically
int y=seek_bar.getLocation().getY();
// Select till which position you want to move the seekbar
TouchAction action=new TouchAction(driver);
//Move it will the end
action.press(start,y).moveTo(end,y).release().perform();
//Move it 40%
int moveTo=(int)(end*0.4);
action.press(start,y).moveTo(moveTo,y).release().perform();
}
这对我来说非常有效
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)