2016-03-04 80 views
6

我有一个自定义的Android搜索栏像这样,以及它可以移动到的位置。它从中间开始:不能移动Android SeekBar与Appium

enter image description here

我想先移动滑块,然后检查它是否保存。我有我使用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始终是相同的价值观,甚至我试图设置块到最左边之前,我把这种方法

我试着用的SendKeys是这样的:

seekbar.sendKeys("0.5"); 

和它的工作:它移动滑块到最左边,而且只用0.5的工作,当我进入的范围内从0到1,它不工作

任何帮助非常赞赏。谢谢

+0

你尝试单击并按住或拖放? –

+0

@PankajKatiyar:我按下并移动并释放 – Ragnarsson

回答

1

我刚刚解决了我的问题:而不是使用按(),我尝试longpress(),它的作品就像一个魅力!我可以将seekbar移到我想要的位置。

0
@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(); 

    } 

这个工作对我非常好