如果页面底部有任何元素或文本,则可以使用UiAutomator2。
如果您使用的是appium,请添加所需的功能’UiAutomator2’。
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UiAutomator2");
现在,如果您有元素的ID,请使用以下函数
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(); } }如果您不知道botton中的任何元素,则必须使用屏幕尺寸
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(); }


