如何在 appium java 中向上滚动到日历中的特定日期
How to scroll up to a specific date in calendar in appium java
我在日历中的年份列表中向上滚动到 select 特定日期,例如“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();
您可以考虑使用 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 command available via SeeTest Appium Extension,它会将代码缩短为 one-liner:
seetest.swipeWhileNotFound("Up", 0, 2000, "NATIVE", "xpath=//android.widget.TextView[@text='1998']", 0, 1000, 5, true)
我在日历中的年份列表中向上滚动到 select 特定日期,例如“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();
您可以考虑使用 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 command available via SeeTest Appium Extension,它会将代码缩短为 one-liner:
seetest.swipeWhileNotFound("Up", 0, 2000, "NATIVE", "xpath=//android.widget.TextView[@text='1998']", 0, 1000, 5, true)