【问题标题】:How to perform scroll in android native app with javascript如何使用javascript在android本机应用程序中执行滚动
【发布时间】:2019-12-15 15:20:44
【问题描述】:

我正在使用 appium 和 webdriverIO 来自动化 android 本机应用程序。我需要执行向下滚动并且我已经使用了

ele.scrollIntoView(true) //this returns not yet implemented error

还有其他方法可以向下滚动吗?

【问题讨论】:

    标签: android appium scrollview native


    【解决方案1】:

    我不使用 java 脚本向下滚动。但我已经用不同的方法给出了详细的答案(通过一些文本、元素和屏幕大小)。请看一下。

    How to reach the end of a scroll bar in appium?

    希望它会有所帮助。

    【讨论】:

    • 使用 UiScrollable 是很好的方法。
    • 是的。它也很有帮助。
    【解决方案2】:

    我找到了一种通过直接从我的代码中调用 JsonWireProtocol api 来执行向下滑动的方法。 https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol

    这是我的代码

    module.exports.scrollAndroid = function (ele) {
        console.log('driver.sessionID = ', driver.sessionId);
        while (!$(ele).isDisplayed()) { . //$(ele)=$(//xpath or any other attribute)
            this.scrollAPICall();
            driver.pause(3000);
        }
    
    };
    module.exports.scrollAPICall = function () {
        var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            console.log("result status >> ", this.status);
            console.log("result text >> ", this.responseText);
        };
    
        url1 = `http://127.0.0.1:4723/wd/hub/session/${driver.sessionId}/touch/flick`;
        xhttp.open('POST', url1);
        console.log("URL >> ", url1)
        xhttp.setRequestHeader("Content-Type", "application/json");
        xhttp.setRequestHeader("charset", "UTF-8");
        xhttp.send(JSON.stringify({
            xspeed: 10,
            yspeed: -100,
        }));
    
    

    如果您想向上滚动,则将 yspeed 设为 + 值。例如:100

    【讨论】:

    • 当appium库提供现成的函数来处理它时,为什么这么头痛?
    【解决方案3】:

    您可以通过执行屏幕向上滑动操作来实现向下滚动。 swipe 类的实现可以从 Boilerplate 项目中找到。 Gestures.js 类具有所有必需的功能。这是class的链接

    请记住,滑动是根据百分比执行的。一旦你实现了这个 Gestures 类,你就可以像下面这样使用它:

    while(!element.isDisplayed()) {
          Gestures.swipeUp(0.5)
    }
    

    【讨论】:

      猜你喜欢
      • 2014-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-28
      • 1970-01-01
      • 2020-02-20
      • 1970-01-01
      • 2012-04-11
      相关资源
      最近更新 更多