无法使用 Appium 移动 Android SeekBar [英] Can't move Android SeekBar with Appium

查看:30
本文介绍了无法使用 Appium 移动 Android SeekBar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像这样定制的 Android 搜索栏,以及它可以移动到的位置.它从中间开始:

I have a customized Android seekbar like this, and the positions where it can move to. And it starts from the middle:

我想先移动滑块,然后检查它是否已保存.我有一个使用 TouchAction 的方法:

I want to move the slider first and then check if it's saved. I have a method which I use 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 始终是相同的值,即使我在调用此方法之前尝试将滑块设置回最左侧

我尝试使用这样的发送键:

I tried with sendkeys like this:

seekbar.sendKeys("0.5");

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

and it worked: it moved the slider to the very left, and it only worked with 0.5, when I entered a number within the range from 0 to 1, it didn't work

非常感谢任何帮助.谢谢

Any help much appreciated. Thanks

推荐答案

我刚刚解决了我的问题:我没有使用 press(),而是尝试了 longpress(),它的效果非常棒!我可以将搜索栏移动到我想要的位置.

I just solved my problem: instead of using press(), I try longpress() and it works like a charm! I can move seekbar where I want.

这篇关于无法使用 Appium 移动 Android SeekBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆