Android 此代码没有';t在真实设备中向下滑动,但在模拟器中工作(使用Appium)
我使用Appium实现自动化,这段代码用于向下滑动,但当我在实际设备上使用它时,它就不起作用了。如何解决实际设备的这一问题Android 此代码没有';t在真实设备中向下滑动,但在模拟器中工作(使用Appium),android,appium,Android,Appium,我使用Appium实现自动化,这段代码用于向下滑动,但当我在实际设备上使用它时,它就不起作用了。如何解决实际设备的这一问题 Dimension dimension = driver.manage().window().getSize(); int start_x = (int) (dimension.width * 0.5); int start_y = (int) (dimension.height * 0.8); int end_x = (int) (dim
Dimension dimension = driver.manage().window().getSize();
int start_x = (int) (dimension.width * 0.5);
int start_y = (int) (dimension.height * 0.8);
int end_x = (int) (dimension.width * 0.5);
int end_y = (int) (dimension.height * 0.2);
new TouchAction(driver).press(PointOption.point(start_x, start_y))
.waitAction(WaitOptions.waitOptions(Duration.ofSeconds(2)))
.moveTo(PointOption.point(end_x, end_y)).release().perform();
如果你想要一个可靠的解决方案,你需要避免使用基于屏幕尺寸的切换,它不是100%准确,即使你知道大小 使用AndroidUIAutomator定位器,您可以在搜索元素旁边自动向上/向下滚动视图,例如,您只知道文本“在这里”:
就个人而言,我强烈建议不要使用文本,而是在中选中
resourceId
和className
。Appium docs也有。谢谢您的建议。但这是正确的刷卡方式,需要等待0.5秒才能工作。UI自动机并非无处不在。
MobileElement element = driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textContains(\"Here it is\"))";