【发布时间】:2019-01-03 03:22:02
【问题描述】:
我无法在使用 Appium 的 Android 应用程序中向下滚动到任何页面的底部。尝试了多种方法,包括在 Stack Overflow 上发现的方法。 (似乎这个挑战很常见。)但是,所有尝试都失败了。
环境:
- Appium 版本:1.6.2
- Appium 客户端:Java (java-client-6.1.0.jar)
- Android 版本:5.1、6.0.1、7.1.1
- Java 版本:jre1.8.0_171
- Selenium 版本:selenium-java-3.13.0
- 应用类型:Cordova(混合);该应用程序是使用 Cordova 构建的,但在运行
System.out.println(driver.getContext());时,结果为NATIVE_APP
请分享任何可以解决此问题的替代方案或改进方案。非常感谢任何有用的建议!
以下总结了尝试过的各种方法:
- 方法:scrollIntoView()(各种实现)
driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(resourceId(\"send-to-email-app\"));").click();
- 来源:Udemy 课程
- 错误:不滚动且无错误
try {
driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(text(\"Send\"))");
}catch(Exception e) {
System.out.println("We got an error scrolling!");
}
- 来源:https://stackoverflow.com/questions/39658626/how-to-scroll-top-to-botton-using-android-driver
- 错误:部分有效:页面向下滚动但不够远
driver.swipe(0, Startpoint,0,scrollEnd,1000);
- 来源:https://stackoverflow.com/questions/39130591/swipe-or-scroll-to-bottom-in-appium-android
- 错误:不推荐使用滑动
...touchAction.longPress(fromX, fromY).moveTo(toX, toY).release().perform();
- 来源:https://stackoverflow.com/questions/44282417/how-to-scroll-with-appium-1-7-1-using-touchaction
- 错误:“驱动程序无法解析”
TouchAction touchAction = new TouchAction(driver);
touchAction.longPress(10, 10).moveTo(x, y).release().perform();
- 来源:https://stackoverflow.com/questions/44282417/how-to-scroll-with-appium-1-7-1-using-touchaction
- 错误:“TouchAction 类型中的方法 longPress(LongPressOptions) 不适用于参数 (int, int)”
...TouchAction touch = new TouchAction(driver);
touch.longPress(co_ordinates[0], co_ordinates[1]).moveTo(dinates[0], dinates[1]).release().perform();
- 来源:https://stackoverflow.com/questions/50304699/how-to-scroll-to-specific-element-inlatest-version-of-appium-using-java
- 错误:“无法解决外卖”
actions.press(startX, startY).waitAction(Duration.ofSeconds(2)).moveTo(endX, endY).release().perform();
- 来源:http://www.automationtestinghub.com/appium-scroll-examples/
- 错误:不推荐使用“按下”操作!
TouchAction().press(el0).moveTo(el1).release();
- 来源:https://stackoverflow.com/questions/49004686/scroll-text-area-with-terms-and-conditions-on-hybrid-app-with-appium
- 错误:“对象类型的方法 press(AndroidElement) 未定义”
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
- 错误:无;它部分有效:页面向下滚动但还不够远!
MobileElement doeButton = driver.findElement(MobileBy.AndroidUIAutomator(
"new UiScrollable(new UiSelector().text(\"Android scrollbar test\")).getChildByText("
+ "new UiSelector().className(\"android.widget.TextView\"), \"Doe\")"));
- 来源:https://stackoverflow.com/a/51003840/9214050
- 错误:“无法解析 UiSelector 参数:使用反射调用此方法时出现问题”
MobileElement sendEmailButton = driver.findElement(MobileBy.AndroidUIAutomator(
"new UiScrollable(new UiSelector().resourceId(\"content\")).scrollIntoView("
+ "new UiSelector().resourceId(\"add-task-button\"))"));
sendEmailButton.click();
- 来源:https://stackoverflow.com/a/51003840/9214050
- 错误:不滚动且无错误
- 来源:http://burnignorance.com/html-tips/making-a-smooth-scroll-view-for-android-ios-in-html/
- 错误:无,但应用不会滚动到页面底部。
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap params = new HashMap();
params.put("direction", "up");
js.executeScript("mobile: swipe", params);
- 来源:https://stackoverflow.com/questions/32387357/i-cant-make-swipe-gesture-work-for-me-in-appium-using-java#
- 错误:“未知的移动命令“滚动”。仅支持 shell、startLogsBroadcast、stopLogsBroadcast 命令。”
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 命令。”
appCapabilities.setCapability("autoWebview", "true");
- 来源:https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/caps.md
- 错误:“线程“主”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 了解更多详情。(警告:服务器未提供任何堆栈跟踪信息)“
【问题讨论】:
-
考虑在最近的类似问题中尝试我建议的答案:stackoverflow.com/questions/51537791/…
-
@AlImran 在尝试采用您的方法时,Eclipse 在最后一行显示有关 press() 的以下内容:“TouchAction 类型中的方法 press(PointOption) 不适用于参数 (整数,整数)”。如何克服?谢谢!
-
@BillHileman 在尝试采用您的第一种方法时,
new TouchActions(driver)行触发了以下错误:“线程中的异常“main”java.lang.ClassCastException:io.appium.java_client.android .AndroidDriver 不能转换为 org.openqa.selenium.interactions.HasTouchScreen”。你有什么建议吗?谢谢! -
我使用 AndroidDriver
作为我的驱动程序实例。这可能与它有关。检查您的 appium java 客户端版本以确保它是最新版本。服务器也是。
标签: java android scroll scrollview appium