【问题标题】:Issue with Scrolling in Android Native app using Appium使用 Appium 在 Android 本机应用程序中滚动的问题
【发布时间】:2016-06-08 16:43:19
【问题描述】:

对于我的原生 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

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

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

【问题讨论】:

    标签: java android scroll appium


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      这个函数对我有用,在你的情况下调用它时为 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);
      }
      

      【讨论】:

      • 感谢代码。我尝试了您所说的,但收到以下错误 org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command。原始错误:无法代理。代理错误:无法将命令代理到远程服务器。原始错误:404 - 未定义(警告:服务器未提供任何堆栈跟踪信息)命令持续时间或超时:14 毫秒知道我做错了什么吗?
      • 您是否能够在您的设备上运行其他脚本,或者它是否会在您调用该函数的位置崩溃?可能还有另一种解决方案,尽管您可能需要花点时间让它滚动到显示元素的位置,您可以尝试 driver.swipe(start_x, start_y, end_x, end_y, duration)。
      • 当我运行以下代码时 driver.findElement(By.id("login_username")).sendKeys("UserID"); Thread.sleep(5000); MobileConfig. driver.findElement(By.id(“User_Password”)).sendKeys(“Password”);线程.sleep(5000); driver.findElement(By.id("login_button")).click();线程.sleep(5000); driver.swipe(560, 1420, 560, 240, 2000); 除了 driver.swipe 行之外,每一行代码都执行成功。我收到此错误 org.openqa.selenium.WebDriverException:Origin An unknown server-side error occurred while processing the command.Could not proxy.代理错误:在下一个评论中继续
      • 所以可能是驱动程序。我正在使用 driver = new AndroidDriver(new URL("appium_IP_goes_Here:4723/wd/hub"), capabilities); 与您获取驱动程序的方式相同吗?
      【解决方案3】:

      使用如下代码:

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

      【讨论】:

      • Driver.swipe 命令是我遇到的问题。 每当我尝试在我的代码中运行该命令时,我都会得到这个错误 处理命令时发生未知的服务器端错误。原始错误:无法代理。代理错误:无法将命令代理到远程服务器。原始错误:404 - 未定义(警告:服务器未提供任何堆栈跟踪信息)命令持续时间或超时:30 毫秒”
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-02-20
      • 2015-11-17
      • 1970-01-01
      • 2019-12-10
      • 2014-06-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多