2016-03-04 14 views
6

Tôi có thanh tìm kiếm Android tùy chỉnh như thế này và các vị trí có thể di chuyển đến. Và nó bắt đầu từ giữa:Không thể di chuyển Android SeekBar bằng Appium

enter image description here

Tôi muốn di chuyển thanh trượt đầu tiên và sau đó kiểm tra nếu nó được lưu. Tôi có một phương pháp mà tôi sử dụng 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(); 
} 

Something Tôi nhận thấy rằng:

  • seekbar không di chuyển ở tất cả
  • GetX và GetY luôn là những giá trị tương tự thậm chí tôi đã cố gắng để thiết lập thanh trượt trở lại rất trái trước khi tôi gọi phương pháp này

tôi đã thử với sendkeys như thế này:

seekbar.sendKeys("0.5"); 

và nó làm việc: nó di chuyển thanh trượt đến rất trái, và nó chỉ làm việc với 0,5, khi tôi bước vào một số trong khoảng từ 0 đến 1, nó đã không làm việc

Bất kỳ giúp nhiều đánh giá cao . Cảm ơn

+0

Bạn đã thử bấm và giữ hoặc kéo và thả? –

+0

@PankajKatiyar: Tôi nhấn và chuyển đến và phát hành – Ragnarsson

Trả lời

1

Tôi vừa giải quyết được vấn đề của mình: thay vì sử dụng nhấn(), tôi thử nhấn và giữ nó hoạt động như một nét duyên dáng! Tôi có thể di chuyển thanh tìm kiếm nơi tôi muốn.

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

    } 

này làm việc cho tôi rất tốt

Các vấn đề liên quan