Search code examples
androidappiumscrollviewnative

How to perform scroll in android native app with javascript


I am using appium and webdriverIO to automate android native app. I need to perform scroll down and i have used

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

is there any other way to scroll down?


Solution

  • I have find a way to perform swipe down by calling JsonWireProtocol api directly from my code. https://github.com/SeleniumHQ/selenium/wiki/JsonWireProtocol

    here is my code

    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,
        }));
    
    

    if you want to scroll up then give yspeed as + value. ex:100