这是一个两阶段的问题。
第一个问题是通过Appium在应用程序上滚动。以前,我们在应用程序的主屏幕上滚动时没有问题,但是现在,主屏幕上的功能具有水平滚动的元素,我们内置到断言方法中的垂直滚动功能现在会失败(在搜索要声明的选定元素时,它们会只是根本不滚动)。下面是我们用来查找元素的方法的示例:
String decode = Arrays.toString(bytes);
Log.d("mytag", decode);
我一直在寻找一种可行的解决方案,但到目前为止,还没有运气。
第二个问题,取决于第一个要解决的问题。并不是什么大问题,而是一个问题。如何在Appium上水平滚动?我见过的所有基于元素的滚动都涉及向下滚动屏幕,而不是仅垂直或水平滚动一个元素。
答案 0 :(得分:0)
您可以在现有代码scrollable(true).instance(0))
中尝试以下代码
如果将appium用作自动化引擎,请添加所需的功能UiAutomator2。
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UiAutomator2");
如果您具有元素的ID,现在使用以下函数,并且在页面上有一个元素的索引为0。
public void scrollByID(String Id, int index) {
try {
driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().resourceId(\""+Id+"\").instance("+index+"));"));
} catch (Exception e) {
e.printStackTrace();
}
}
使用文本滚动
public void scrollByText(String menuText) {
try {
driver.findElement(MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector().scrollable(true).instance(0)).scrollIntoView(new UiSelector().textMatches(\"" + menuText + "\").instance(0));"));
} catch (Exception e) {
e.printStackTrace();
}
}
滚动显示屏幕尺寸:
public void scrollToBottom() {
int x = driver.manage().window().getSize().width / 2;
int start_y = (int) (driver.manage().window().getSize().height * 0.2);
int end_y = (int) (driver.manage().window().getSize().height * 0.8);
TouchAction dragNDrop = new TouchAction(driver)
.press(PointOption.point(x,start_y)).waitAction(WaitOptions.waitOptions(Duration.ofMillis(500)))
.moveTo(PointOption.point(x, end_y))
.release();
dragNDrop.perform();
}