【问题标题】:How to scroll using coordinates with appium如何使用 appium 的坐标滚动
【发布时间】:2020-01-25 04:42:00
【问题描述】:

我正在尝试使用以下方法在原生 android 应用中滚动

Dimension size = driver.manage().window().getSize();
int starty = (int) (size.height * 0.80);
int endy = (int) (size.height * 0.20);
int startx = size.width / 2;

driver.swipe(startx, starty, startx, endy, 3000);
Thread.sleep(2000);

但是在driver.swipe 它给了我一个错误提示

方法 swipe(int, int, int, int, int) 对于 AndroidDriver 类型未定义

谁能帮我解决这个问题?我一直在寻找解决方案,但我没有运气。

【问题讨论】:

    标签: java android selenium automation appium


    【解决方案1】:

    您可以使用TouchAction 代替.swipe

    TouchAction action = new TouchAction(driver);
    action.press(x, y).moveTo(x, y).release().perform();
    

    你也可以用PointOption实现x y,像这样:

    1. .press(new PointOption().withCoordinates(x, y))

      或者

    2. .press(PointOption.point(x, y))

    导入后:

    import io.appium.java_client.TouchAction;
    

    TouchAction

    PointOption

    【讨论】:

    • 嘿兄弟,它说 TouchAction 类型中的方法 press(PointOption) 不适用于参数 (int, int)
    • press(PointOption) 尝试使用以下值插入:press(new PointOption().withCoordinates(value, value))
    • 感谢兄弟,但你知道是否有办法让它滚动得更慢吗?它滚动得非常快
    • 像这样:.press(...).waitAction(Duration.ofSeconds(2)).moveTo(...)。您需要导入:import java.time.Duration;
    【解决方案2】:

    试试这个技术,而不是 appium 方法。

    JavascriptExecutor js = (JavascriptExecutor) driver;
    HashMap<String, String> scrollObject = new HashMap<>();
    scrollObject.put("direction", "down");
    js.executeScript("mobile: swipe", scrollObject);
    

    【讨论】:

      猜你喜欢
      • 2022-07-09
      • 1970-01-01
      • 2019-08-08
      • 2017-11-01
      • 2019-09-25
      • 2021-08-02
      • 1970-01-01
      • 2014-12-26
      • 2019-01-22
      相关资源
      最近更新 更多