我正在日历中的年份列表中向上滚动以选择特定的日期,例如“ 1998”。那么如何向上滚动到给定年份并单击该年份呢?
此给定代码先向上滚动一点,然后再次向下滚动两次。 This image is shows latest calendar ui
MobileElement element = (MobileElement) driver
.findElementByAndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(\"" + text + "\").instance(0))");
element.click();
答案 0 :(得分:2)
您可以考虑使用mobile:shell
command连续向上滚动直到所需的年份出现在屏幕上,示例代码如下:
Dimension windowSize = driver.manage().window().getSize();
Map<String, Object> args = new HashMap<>();
args.put("command", "input");
args.put("args", Lists.newArrayList("swipe", windowSize.width / 2,
windowSize.height / 2, windowSize.width / 2, windowSize.height));
while (driver.findElements(By.xpath("//android.widget.TextView[@text='1998']")).size() == 0) {
driver.executeScript("mobile: shell", args);
}
driver.findElement(By.xpath("//android.widget.TextView[@text='1998']")).click();
演示:
通过SwipeWhileNotFound提供的SeeTest Appium Extension命令甚至更容易选择,它将代码缩短为单行代码:
seetest.swipeWhileNotFound("Up", 0, 2000, "NATIVE", "xpath=//android.widget.TextView[@text='1998']", 0, 1000, 5, true)