是否可以使用类似 iOS 的内容(如 AndroidUIAutomator)滚动到某个元素?

Is it possible to scroll to an element using something similar in iOS like AndroidUIAutomator?

正如标题所暗示的,这是关于在本机 iOS 应用程序中的 Appium 中滚动。在 Android 应用程序中,我们使用这个:

MobileBy.AndroidUIAutomator("new UiScrollable(new UiSelector()" +
     ".scrollable(true)).scrollIntoView(new UiSelector().resourceId(\"" + myVariable +\""));");

这适用于我们的 Android 应用程序,我想知道是否有类似的东西可用于 iOS。是否可以选择使用此方法?

MobileBy.iOSClassChain()

我没有这方面的经验,而且我在文档中找不到任何内容告诉我是否可以使用此方法滚动到一个元素,并可以选择启用或在字符串中传递它传递给它。它只是一种比 XPath 更快的定位元素的方法,还是可以以与 AndroidUIAutomator 类似的方式使用?

上面提到的 Android 方法比我们之前使用的任何 touchAction 都更可靠、更快,因此我也想切换到 iOS 中的类似方法。

执行受控滚动的推荐最佳做法是使用 Appium“mobile:scroll”脚本命令。此命令是使用 executeScript() 方法执行的。

RemoteWebElement element = (RemoteWebElement)driver.findElement(By.className("XCUIElementTypeTable"));
String elementID = element.getId();
HashMap<String, String> scrollObject = new HashMap<String, String>();
scrollObject.put("element", elementID); // Only for ‘scroll in element’
scrollObject.put("direction", "down");
driver.executeScript("mobile:scroll", scrollObject);

“element”: The id of the element that you want to scroll – “element” must be scrollable.

“direction”: “up”, “down”, “left, “right”.

有关滚动的详细信息,请查看 Scrolling in IOS

 JavascriptExecutor js = (JavascriptExecutor) driver;
 HashMap<String, String> swipeObject = new HashMap<String, String>();
 swipeObject.put("direction", "down"); //up for swipe
 swipeObject.put("startX", "90");
 swipeObject.put("startY", "400");
 swipeObject.put("endX", "90"); //"90");
 swipeObject.put("endY", "350"); //"200");
 swipeObject.put("duration", "2000");
 js.executeScript("mobile: scroll", swipeObject);