我无法使用Appium向下滚动到Android应用中任何页面的底部。尝试了多种方法,包括在Stack Overflow上找到的方法。 (看来这个挑战很普遍。)但是,所有尝试都失败了。
环境:
System.out.println(driver.getContext());
时,结果为NATIVE_APP
请分享可以解决此问题的所有替代方案或改进方案。任何有用的建议,将不胜感激!
以下总结了尝试的各种方法:
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");
答案 0 :(得分:3)
作为上述建议选项的一种变体,这是与TouchAction
和press
方法结合使用的另一种实现moveTo
的方法。这导致屏幕向下滑动。您可能需要简单地将坐标调整为最适合客户的方式:
new TouchAction(driver).press(PointOption.point(550, 640)).waitAction().moveTo(PointOption.point(550, 60)).release().perform();
有关其他信息,您可以查看以下参考: