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

Unable to scroll Android app with Appium using Java Client

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

环境:

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

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

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

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

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

  7. 方法:touchAction.longPress + moveTo
  8. ...touchAction.longPress(fromX, fromY).moveTo(toX, toY).release().perform();
    • 来源:
    • 错误:"driver cannot be resolved"

  9. 方法:touchAction.longPress + moveTo
  10. TouchAction touchAction = new TouchAction(driver); touchAction.longPress(10, 10).moveTo(x, y).release().perform();
    • 来源:
    • 错误:"The method longPress(LongPressOptions) in the type TouchAction is not applicable for the arguments (int, int)"

  11. 方法:touch.longPress + moveTo
  12. ...TouchAction touch = new TouchAction(driver); touch.longPress(co_ordinates[0], co_ordinates[1]).moveTo(dinates[0], dinates[1]).release().perform();
    • 来源:
    • 错误:"takeaway cannot be resolved"

  13. 方法:moveTo + 使用坐标
  14. actions.press(startX, startY).waitAction(Duration.ofSeconds(2)).moveTo(endX, endY).release().perform();
    • 来源:http://www.automationtestinghub.com/appium-scroll-examples/
    • 错误:'press' 操作已弃用!

  15. 方法:使用 Press Approach 滑动 + moveTo
  16. TouchAction().press(el0).moveTo(el1).release();
    • 来源:
    • 错误:"The method press(AndroidElement) is undefined for the type Object"

  17. 方法:touchAction 'tap' 使用坐标
  18. 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
    • 错误:None;它部分起作用:页面向下滚动但还不够远!

  19. 方法:UiScrollable > 指定父可滚动框架和子元素
  20. MobileElement doeButton = driver.findElement(MobileBy.AndroidUIAutomator( "new UiScrollable(new UiSelector().text(\"Android scrollbar test\")).getChildByText(" + "new UiSelector().className(\"android.widget.TextView\"), \"Doe\")"));
    • 来源:
    • 错误:"Could not parse UiSelector argument: problem using reflection to call this method"

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

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

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

  27. 方法:HashMap + scrollObject.put
  28. 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/
    • 错误:"Unknown mobile command "滚动”。仅支持 shell、startLogsBroadcast、stopLogsBroadcast 命令。”

  29. 方法:将应用的上下文从 "native" 调整为 "webview"(因为它是 Cordova 应用)
  30. appCapabilities.setCapability("autoWebview", "true");
    • 来源:https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md
    • 错误:"Exception in thread "main" org.openqa.selenium.WebDriverException:无法创建新会话,因为 'createSession' 找不到或无法访问采用 HttpClient、InputStream 和 long 的 'createSession'。 “
    • 错误:"org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: No Chromedriver found that can automate Chrome '58.0.3029'. See https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/web/chromedriver.md for more details. (WARNING: The server did not provide any stacktrace information)"

作为上述选项的变体,这里是另一种实现 TouchActionpressmoveTo 方法相结合的方法,对我有用。这会导致屏幕向下滑动。您可能需要简单地将坐标调整为最适合您的客户端的坐标:

new TouchAction(driver).press(PointOption.point(550, 640)).waitAction().moveTo(PointOption.point(550, 60)).release().perform();

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