如何使用javascript在Android本机应用程序中执行滚动

我正在使用appium和webdriverIO来自动化android native app。我需要执行向下滚动,并且已经使用了

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

还有其他向下滚动的方式吗?

zhu033033 回答:如何使用javascript在Android本机应用程序中执行滚动

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

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

希望这会有所帮助。

,

我找到了一种直接从代码中调用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

,

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

的链接

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

while(!element.isDisplayed()) {
      Gestures.swipeUp(0.5)
}
本文链接:https://www.f2er.com/2942571.html

大家都在问