无法使用 Java 客户端使用 Appium 滚动 Android 应用程序

mc-*_*sm9 5 java android scroll scrollview appium

我无法使用 Appium 向下滚动到 Android 应用程序中任何页面的底部。尝试了多种方法,包括在 Stack Overflow 上找到的方法。(这个挑战似乎很常见。)然而,所有的尝试都失败了。

环境:

  • Appium 版本:1.6.2
  • Appium 客户端:Java (java-client-6.1.0.jar)
  • 安卓版本:5.1、6.0.1、7.1.1
  • Java版本:jre1.8.0_171
  • 硒版本:selenium-java-3.13.0
  • 应用类型:Cordova(混合);该应用程序是用 Cordova 构建的,但在运行时System.out.println(driver.getContext());,结果是NATIVE_APP

请分享可以解决此问题的任何替代方案或改进。非常感谢任何有用的建议!

以下总结了尝试的各种方法:

  1. 方法:scrollIntoView()(各种实现)
  2. driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(resourceId(\"send-to-email-app\"));").click();
  • 来源:Udemy 课程
  • 错误:不滚动且没有错误

  • 方法:尝试 catch > scrollIntoView()
  • try { driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(text(\"Send\"))"); }catch(Exception e) { System.out.println("We got an error scrolling!"); }
    • 来源:/sf/ask/2776103851/
    • 错误:部分有效:页面向下滚动但不够远

  • 方法:滑动
  • driver.swipe(0, Startpoint,0,scrollEnd,1000);
    • 来源:/sf/ask/2739141401/
    • 错误:不推荐使用滑动

  • 方法:touchAction.longPress + moveTo
  • ...touchAction.longPress(fromX, fromY).moveTo(toX, toY).release().perform();
    • 来源:/sf/ask/3099769221/
    • 错误:“无法解析驱动程序”

  • 方法:touchAction.longPress + moveTo
  • TouchAction touchAction = new TouchAction(driver); touchAction.longPress(10, 10).moveTo(x, y).release().perform();
    • 来源:/sf/ask/3099769221/
    • 错误:“TouchAction 类型中的 longPress(LongPressOptions) 方法不适用于参数 (int, int)”

  • 方法:touch.longPress + moveTo
  • ...TouchAction touch = new TouchAction(driver); touch.longPress(co_ordinates[0], co_ordinates[1]).moveTo(dinates[0], dinates[1]).release().perform();
    • 来源:/sf/ask/3521328961/
    • 错误:“外卖无法解决”

  • 方法:moveTo + 使用坐标
  • actions.press(startX, startY).waitAction(Duration.ofSeconds(2)).moveTo(endX, endY).release().perform();
    • 来源:http://www.automationtestinghub.com/appium-scroll-examples/
    • 错误:不推荐使用“按下”操作!

  • 方法:使用 Press Approach 滑动 + moveTo
  • TouchAction().press(el0).moveTo(el1).release();
    • 来源:/sf/ask/3430328051/
    • 错误:“未定义对象类型的方法 press(AndroidElement)”

  • 方法:touchAction 'tap' 使用坐标
  • TouchAction touchAction = new TouchAction(driver); touchAction.tap(PointOption.point(x, y)).perform();
    • 来源:https://discuss.appium.io/t/scrolling-to-element-in-android-app-using-java/17208
    • 错误:无;它部分有效:页面向下滚动但不够远!

  • 方法:UiScrollable > 指定父滚动框架和子元素
  • MobileElement doeButton = driver.findElement(MobileBy.AndroidUIAutomator( "new UiScrollable(new UiSelector().text(\"Android scrollbar test\")).getChildByText(" + "new UiSelector().className(\"android.widget.TextView\"), \"Doe\")"));
    • 来源:/sf/answers/3570268831/
    • 错误:“无法解析 UiSelector 参数:使用反射调用此方法时出现问题”

  • 方法:UiScrollable > 指定父滚动框架和'scrollIntoView'子元素
  • MobileElement sendEmailButton = driver.findElement(MobileBy.AndroidUIAutomator( "new UiScrollable(new UiSelector().resourceId(\"content\")).scrollIntoView(" + "new UiSelector().resourceId(\"add-task-button\"))")); sendEmailButton.click();
    • 来源:/sf/answers/3570268831/
    • 错误:不滚动且没有错误

  • 方法:使用 CSS 样式将页面元素的“scrollable”属性从“false”更改为“true”
    • 来源:http://burnignorance.com/html-tips/making-a-smooth-scroll-view-for-android-ios-in-html/
    • 错误:无,但应用不会滚动到页面底部。

  • 方法:触摸动作:“移动:滑动”,“移动:滚动”(http://appium.io/docs/en/writing-running-appium/touch-actions/)
  • JavascriptExecutor js = (JavascriptExecutor) driver; HashMap params = new HashMap(); params.put("direction", "up"); js.executeScript("mobile: swipe", params);
    • 来源:/sf/ask/2267115021/#
    • 错误:“未知的移动命令“滚动”。仅支持 shell、startLogsBroadcast、stopLogsBroadcast 命令。”

  • 方法:HashMap + scrollObject.put
  • JavascriptExecutor js = (JavascriptExecutor) driver; HashMap scrollObject = new HashMap(); scrollObject.put("direction", "down"); js.executeScript("mobile: scroll", scrollObject);
    • 来源:http://appium.io/docs/en/writing-running-appium/touch-actions/
    • 错误:“未知的移动命令“滚动”。仅支持 shell、startLogsBroadcast、stopLogsBroadcast 命令。”

  • 方法:将应用程序的上下文从“本机”调整为“webview”(因为它是 Cordova 应用程序)
  • appCapabilities.setCapability("autoWebview", "true");
    • 来源:https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md
    • 错误:“线程“main”中的异常 org.openqa.selenium.WebDriverException:无法创建新会话,因为使用 HttpClient、InputStream 和 long 的“createSession”未找到或无法访问。”
    • 错误:“org.openqa.selenium.WebDriverException:处理命令时发生未知的服务器端错误。原始错误:没有找到可以自动化Chrome'58.0.3029'的Chromedriver。见https://github.com/appium/ appium/blob/master/docs/en/writing-running-appium/web/chromedriver.md 了解更多详情。(警告:服务器没有提供任何堆栈跟踪信息)”

    toa*_*sty 6

    正如上面所提出的方案的变化,这里是实现的另一种方式TouchAction结合press,并moveTo为我工作的方法。这会导致向下滑动屏幕。您可能需要简单地将坐标调整为最适合您的客户端:

    new TouchAction(driver).press(PointOption.point(550, 640)).waitAction().moveTo(PointOption.point(550, 60)).release().perform();
    
    Run Code Online (Sandbox Code Playgroud)

    有关其他信息,您可以查看这些参考资料:

    • 这是我一直在寻找的解决方案!我想建议一个小的改进:它只使用 .longPress(...) 而不是 .press(...).waitAction() 它对我来说很好用。Appium 的在线文档和示例还有很多不足之处,但是您的示例非常清楚,谢谢。我对 x/y 点参数很感兴趣,文档只是说“pointoptions”而没有示例。 (2认同)