繁体   English   中英

使用 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

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

有什么我做错了吗??? 我似乎无法弄清楚。

您使用了 Selendroid 模式,该模式不支持 UiAutomator By 方法。 您可以通过将所需的功能automationName Appium设置为 Appium,将您的 appium 运行模式更改为Appium

这个函数对我有用,在你的情况下调用它时为 elementName 放入“帐户”。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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