【问题标题】:Can't move Android SeekBar with Appium无法使用 Appium 移动 Android SeekBar
【发布时间】:2016-06-18 09:48:47
【问题描述】:

我有一个像这样定制的 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();
}

我注意到的一点:

  • seekbar 根本不动
  • getX 和 getY 始终是相同的值,即使我在调用此方法之前尝试将滑块设置回最左侧

我尝试过这样的发送键:

seekbar.sendKeys("0.5");

它起作用了:它把滑块移到了最左边,它只适用于 0.5,当我输入一个从 0 到 1 范围内的数字时,它不起作用

非常感谢任何帮助。谢谢

【问题讨论】:

  • 您尝试点击并按住还是拖放?
  • @PankajKatiyar:我按下并移动到并释放

标签: android automated-tests appium seekbar android-seekbar


【解决方案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();

    }

这对我很有效

【讨论】:

  • 我在视频播放器中有一个搜索栏,但是这个 sn-p 不起作用
【解决方案2】:

我刚刚解决了我的问题:我没有使用 press(),而是尝试使用 longpress(),它就像一个魅力!我可以将搜索栏移动到我想要的位置。

【讨论】:

    【解决方案3】:

    我试过这样 seekbar.sendKeys("50"); 它对我有用。(0(min) - 100(max))

    【讨论】:

      猜你喜欢
      • 2019-05-01
      • 1970-01-01
      • 2018-02-05
      • 2020-12-01
      • 1970-01-01
      • 2015-06-22
      • 1970-01-01
      • 2020-05-02
      • 1970-01-01
      相关资源
      最近更新 更多