使用 Appium 在 Android 本机应用程序中滚动时出现问题

Issue with Scrolling in Android Native app using Appium

对于我的原生 Android 应用程序,在过去的 2 周里,我一直在尝试让 appium 在我的原生应用程序上向下滚动。我试过了 driver.scrollTo("Accounts"); 然后我得到了这个错误

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

以及我发现的许多其他示例。似乎没有任何效果。这是我尝试过的最新示例。

使用 appium 1.5.2 和 appium java 客户端版本:“3.3.0”。当我尝试 运行 以下代码时。

    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();

然后我收到此错误消息

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

我不知所措。为了点击一个元素,它必须在屏幕上可见。为了让这个元素出现在屏幕上,我需要向下滚动到它。

我做错了什么吗???我就是想不通。

这个函数对我有用,在你的情况下调用它时为 elementName 输入 "Accounts"。

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

使用如下代码:

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

您使用的是Selendroid模式,不支持UiAutomator By方法。 您可以通过将所需的功能 automationName 设置为 Appium

来将您的 appium 运行 模式更改为 UiAutomator