gpt4 book ai didi

java - 如何在appium java中向上滚动到日历中的特定日期

转载 作者:行者123 更新时间:2023-12-01 19:38:59 25 4
gpt4 key购买 nike

我在日历中的年份列表中向上滚动以选择特定日期,例如“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();

演示:

enter image description here

<小时/>

更简单的选择是 SwipeWhileNotFound命令可通过SeeTest Appium Extension获得,它将把代码缩短为一行:

seetest.swipeWhileNotFound("Up", 0, 2000, "NATIVE", "xpath=//android.widget.TextView[@text='1998']", 0, 1000, 5, true)

关于java - 如何在appium java中向上滚动到日历中的特定日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56075203/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com