【问题标题】:Appium - How to scroll down using UiAutomator2 and WebdriverIO with React Native (Android) and JavaScriptAppium - 如何使用带有 React Native (Android) 和 JavaScript 的 UiAutomator2 和 WebdriverIO 向下滚动
【发布时间】:2020-11-24 00:52:52
【问题描述】:

无论我尝试什么,我都无法让我的 React Native (Android) 应用使用 Appium 向下滚动。

我正在使用 UiAutomator2 和 WebdriverIO。

我的代码如下所示:

scrollUntilDisplayed(element: WebdriverIO.Element) {
    const dimensions = driver.getWindowSize();
    touchScroll(10, 100);
}

代替touchScroll,我尝试了以下调用:

  • driver.touchScroll(offsetX, offsetY) - 引发错误 (invalid argument: java.lang.IllegalArgumentException: ScrollToModel: The mandatory field 'params' is not present in JSON)
  • driver.touchScroll(offsetX, offsetY, element) - 引发错误 (invalid argument: java.lang.IllegalArgumentException: ScrollToModel: The mandatory field 'params' is not present in JSON)
  • browser.execute("mobile: scroll", {direction: 'down'}); - 引发错误 (unknown error: An unknown server-side error occurred while processing the command. Original error: Both strategy and selector arguments must be provided)
  • driver.touchFlick(0, dimensions.height, undefined, 10000, 10000, 10000); - 什么都不做;一直坐到 Appium 超时
  • element.scrollIntoView(); - 什么都不做

【问题讨论】:

    标签: javascript react-native appium webdriver-io android-uiautomator


    【解决方案1】:

    由于 ReactNative 具有 NATIVE_APP 上下文(作为常规 Android 应用程序),您可以使用 uiautomator selector

    const bottomElementSelector = `new UiScrollable(new UiSelector().scrollable(true)).scrollIntoView(new UiSelector().text("Element label text"))`
    const bottomEl = $(`android=${bottomElementSelector}`)
    

    使用可滚动选择器搜索元素应将焦点向下移动到该元素

    注意:确保您在 Appium 功能中使用 UiAutomator2

    【讨论】:

    • 我最终通过description 进行查询,因为我更愿意查询辅助功能标签而不是内部文本。但两者都按预期工作:)
    • 你说得对,就维护而言,使用文本是一种糟糕的方式。我只是想做一个最简单的例子:)
    猜你喜欢
    • 2020-06-27
    • 2017-06-19
    • 1970-01-01
    • 2021-11-27
    • 2022-07-09
    • 2021-10-26
    • 1970-01-01
    • 2018-03-14
    • 2019-12-24
    相关资源
    最近更新 更多