2016-03-04 78 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(); 

    } 

這個工作對我非常好