简体   繁体   中英

Issue with Scrolling in Android Native app using Appium

For my Native Android App , I have been trying for the past 2 weeks to get appium to scroll down on my native app. I have tried driver.scrollTo("Accounts"); Then I got this error

[org.openqa.selenium.WebDriverException: CATCH_ALL: io.selendroid.server.common.exceptions.SelendroidException: method (by) not found: -android uiautomator

and many other examples that I have found. Nothing seems to work . This is the latest example that I have tried .

Using appium 1.5.2 and appium java client version: '3.3.0'. When I try to run the following code.

    TouchAction tAction=new TouchAction(driver);
    int startx = driver.findElement(By.id("line_chart_line_chart")).getLocation().getX();
    int starty = driver.findElement(By.id("line_chart_line_chart")).getLocation().getY();
    int endx = driver.findElement(By.id("actionBarLogo")).getLocation().getX();
    int endy = driver.findElement(By.id("actionBarLogo")).getLocation().getY();
    System.out.println(startx + " ::::::: " + starty + " ::::::: " + endx +  " ::::::: " +  endy);
    //  This is what the console printed out  startX=560 ::::::: starty=1420 ::::::: endx=560 ::::::: endy=240  
    //First tap on the screen and swipe up using moveTo function
    tAction.press(startx,starty).moveTo(endx,endy).release().perform();

Then I get this error message

org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Could not proxy. Proxy 
error: Could not proxy command to remote server. Original error: 404 - undefined (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 27 milliseconds

I am at a loss on what to do. In order to click on an element it has to be visible on the screen . In order for this element to appear on the screen I need to scroll down to it.

Is there something that I am doing wrong??? I just can't seem to figure it out.

You used Selendroid mode, which does not support UiAutomator By method. You can change your appium running mode to UiAutomator by setting desired capability automationName to Appium

This function does the trick for me, put in "Accounts" for elementName when calling it in your case.

public static void scrollToElementAndroid(AndroidDriver driver, String elementName, boolean scrollDown) {
    String listID = ((RemoteWebElement) driver.findElementByAndroidUIAutomator("new UiSelector().className(android.widget.ListView)")).getId();
    String direction;
    if (scrollDown) {
        direction = "down";
    } else {
        direction = "up";
    }
    HashMap<String, String> scrollObject = new HashMap<String, String>();
    scrollObject.put("direction", direction);
    scrollObject.put("element", listID);
    scrollObject.put("text", elementName);
    driver.executeScript("mobile: scrollTo", scrollObject);
}

Use code like below:

Dimension size = driver.manage().window().getSize();
int x = size.width / 2;
int endy = (int) (size.height * 0.75);
int starty = (int) (size.height * 0.20);
driver.swipe(x, starty, x, endy, 1000);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM