我无法使用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
请分享任何可以解决此问题的替代方案或改进方案。非常感谢任何有用的建议!
以下总结了尝试的各种方法:
- 方法:scrollIntoView()(各种实现)
- 来源:Udemy课程
- 错误:不滚动且无错误
- 方法:尝试catch>scrollIntoView()
- 来源:https://stackoverflow.com/questions/39658626/how-to-scroll-top-to-botton-using-android-driver
- 错误:部分工作:页面向下滚动但不够远
- 方法:轻扫
- 来源:https://stackoverflow.com/questions/39130591/swipe-or-scroll-to-bottom-in-appium-android
- 错误:不赞成滑动
- 方法:touchAction.longPress+moveTo
- 来源:https://stackoverflow.com/questions/44282417/how-to-scroll-with-appium-1-7-1-using-touchaction
- 错误:"无法解析驱动程序">
- 方法:touchAction.longPress+moveTo
- 来源:https://stackoverflow.com/questions/44282417/how-to-scroll-with-appium-1-7-1-using-touchaction
- 错误:"TouchAction类型中的方法longPress(LongPressOptions)不适用于参数(int,int)">
- 方法:touch.longPress+moveTo
- 来源:https://stackoverflow.com/questions/50304699/how-to-scroll-to-specific-element-inlatest-version-of-appium-using-java
- 错误:"无法解决外卖">
- 方法:moveTo+使用坐标
- 来源:http://www.automationtestinghub.com/appium-scroll-examples/
- 错误:"press"操作已弃用
- 方法:使用Press方法滑动+moveTo
- 来源:https://stackoverflow.com/questions/49004686/scroll-text-area-with-terms-and-conditions-on-hybrid-app-with-appium
- 错误:"Object类型的方法press(AndroidElement)未定义">
- 方法:触摸操作使用坐标"点击">
- 来源:https://discuss.appium.io/t/scrolling-to-element-in-android-app-using-java/17208
- 错误:无;它部分起作用:页面向下滚动,但不够远
- 方法:UiScrollable>指定父可滚动框架和子元素
- 来源:https://stackoverflow.com/a/51003840/9214050
- 错误:"无法分析UiSelector参数:使用反射调用此方法时出现问题">
- 方法:UiScrollable>指定父可滚动框架和"scrollIntoView"子元素
- 来源:https://stackoverflow.com/a/51003840/9214050
- 错误:不滚动且无错误
- 方法:使用CSS样式将页面元素的"可滚动"属性从"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/)
- 来源:https://stackoverflow.com/questions/32387357/i-cant-make-swipe-gesture-work-for-me-in-appium-using-java#
- 错误:"未知的移动命令"scroll"。只支持shell、startLogsRoadcast和stopLogsRoadCast命令。">
- 方法:HashMap+scrollObject.put
- 来源:http://appium.io/docs/en/writing-running-appium/touch-actions/
- 错误:"未知的移动命令"scroll"。只支持shell、startLogsRoadcast和stopLogsRoadCast命令。">
- 方法:将应用程序的上下文从"原生"调整为"网络视图"(因为它是Cordova应用程序)
- 来源: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了解更多详细信息。(警告:服务器未提供任何堆栈竞争信息)">
driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(resourceId("send-to-email-app"));").click();
try {
driver.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector()).scrollIntoView(text("Send"))");
}catch(Exception e) {
System.out.println("We got an error scrolling!");
}
driver.swipe(0, Startpoint,0,scrollEnd,1000);
...touchAction.longPress(fromX, fromY).moveTo(toX, toY).release().perform();
TouchAction touchAction = new TouchAction(driver);
touchAction.longPress(10, 10).moveTo(x, y).release().perform();
...TouchAction touch = new TouchAction(driver);
touch.longPress(co_ordinates[0], co_ordinates[1]).moveTo(dinates[0], dinates[1]).release().perform();
actions.press(startX, startY).waitAction(Duration.ofSeconds(2)).moveTo(endX, endY).release().perform();
TouchAction().press(el0).moveTo(el1).release();
TouchAction touchAction = new TouchAction(driver);
touchAction.tap(PointOption.point(x, y)).perform();
MobileElement doeButton = driver.findElement(MobileBy.AndroidUIAutomator(
"new UiScrollable(new UiSelector().text("Android scrollbar test")).getChildByText("
+ "new UiSelector().className("android.widget.TextView"), "Doe")"));
MobileElement sendEmailButton = driver.findElement(MobileBy.AndroidUIAutomator(
"new UiScrollable(new UiSelector().resourceId("content")).scrollIntoView("
+ "new UiSelector().resourceId("add-task-button"))"));
sendEmailButton.click();
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap params = new HashMap();
params.put("direction", "up");
js.executeScript("mobile: swipe", params);
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap scrollObject = new HashMap();
scrollObject.put("direction", "down");
js.executeScript("mobile: scroll", scrollObject);
appCapabilities.setCapability("autoWebview", "true");
作为上述选项的变体,这里有另一种将TouchAction
与适用于我的press
和moveTo
方法相结合的实现方式。这会导致屏幕向下滑动。您可能需要简单地将坐标调整为对您的客户最有效的坐标:
new TouchAction(driver).press(PointOption.point(550, 640)).waitAction().moveTo(PointOption.point(550, 60)).release().perform();
有关更多信息,您可以查看以下参考资料:
- Appium网站:http://appium.io/docs/en/writing-running-appium/touch-actions/
- 教程:https://www.youtube.com/watch?v=9rHe0r6YsVg