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

Java 使用Appium在Android本机应用程序中滚动时出现问题,java,android,scroll,appium,Java,Android,Scroll,Appium,对于我的原生Android应用程序,在过去的两周里,我一直在尝试让appium在我的原生应用程序上向下滚动。我尝试了driver.scrollTo(“帐户”) 然后我犯了这个错误 [org.openqa.selenium.WebDriverException: CATCH_ALL: io.selendroid.server.common.exceptions.SelendroidException: method (by) not found: -android uiautomator 还有我

对于我的原生Android应用程序,在过去的两周里,我一直在尝试让appium在我的原生应用程序上向下滚动。我尝试了
driver.scrollTo(“帐户”)
然后我犯了这个错误

[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);
}
publicstaticvoidScrollToElementAndRoid(AndroidDriver驱动程序,String elementName,boolean scrollDown){
字符串listID=((RemoteWebElement)driver.findelementbyandoriduiautomator(“new-UiSelector().className(android.widget.ListView)”).getId();
弦方向;
如果(向下滚动){
方向=“向下”;
}否则{
方向=“向上”;
}
HashMap scrollObject=新建HashMap();
滚动对象。放置(“方向”,方向);
scrollObject.put(“元素”,listID);
scrollObject.put(“text”,elementName);
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,谢谢您的代码。我尝试了您所说的,但得到了以下错误org.openqa.selenium.WebDriverException:处理命令时发生未知的服务器端错误。原始错误:无法代理。代理错误:无法将命令代理到远程服务器。原始错误:404-未定义(警告:服务器未提供任何stacktrace信息)命令持续时间或超时:14毫秒知道我做错了什么吗?您是否能够在设备上运行其他脚本,或者它是否在调用函数的位置崩溃?可能还有另一种解决方案,尽管您可能需要玩一些游戏才能让它滚动到显示元素的位置,但您可以尝试driver.swip(start\u x,start\u y,end\u x,end\u y,duration)。当我运行以下代码驱动程序时。findElement(By.id(“login\u username”).sendKeys(“UserID”);Thread.sleep(5000);MobileConfig.driver.findElement(By.id(“用户密码”)).sendKeys(“密码”);thread.sleep(5000);driver.findElement(By.id(“登录按钮”))。单击();thread.sleep(5000);driver.swipe(560、1420、560、240、2000);除了driver.swipe行之外,代码的每一行都成功执行。我在org.openqa.selenium.WebDriverException:Origin处理命令时发生未知的服务器端错误。无法代理。代理错误:下一次启动时继续,因此可能是驱动程序。我使用的是driver=new AndroidDriver(new URL(“),能力);这与获取驱动程序的方式相同吗?driver.swipe命令是我遇到的问题。每当我尝试在代码中运行该命令时,都会出现此错误。处理该命令时出现未知服务器端错误。原始错误:无法代理。代理错误:无法将命令代理到远程服务器。原始错误:404-未定义(警告:服务器未提供任何stacktrace信息)命令持续时间或超时:30毫秒“