您的方法有点错误,当涉及到Appium测试时,您不能使用Element.scrollIntoView ,因为您仅限于Appium 可以理解的特定移动命令列表。
您需要重构代码以使用mobile:shellcommand,例如:
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.view.View[@text='Karnataka']")).size() == 0) {
driver.executeScript("mobile: shell", args);
}
driver.findElement(By.xpath("//android.view.View[@text='Karnataka']")).click();
或者,您可以通过SeeTest Appium Extensions使用SwipeWhileNotFound命令
seetest.swipeWhileNotFound("Up", 0, 2000, "NATIVE", "xpath=//android.view.View[@text='Karnataka']", 0, 1000, 5, true)