【问题标题】:Is it possible to scroll to an element using something similar in iOS like AndroidUIAutomator?是否可以在 iOS 中使用类似 AndroidUIAutomator 的东西滚动到一个元素?
【发布时间】:2019-07-12 00:59:16
【问题描述】:

正如标题已经暗示的那样,这是关于在原生 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 appium-ios appium-android


    【解决方案1】:

    执行受控滚动的推荐最佳实践是使用 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”:要滚动的元素的id——“element”必须是可滚动的。

    “方向”:“上”、“下”、“左”、“右”。

    有关滚动的更多信息,请查看Scrolling in IOS

    【讨论】:

      【解决方案2】:
       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);
      

      【讨论】:

      • 在代码中添加一个简短的解释会很好
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-18
      • 1970-01-01
      相关资源
      最近更新 更多