【问题标题】:How to change iOS slider value through Appium/WebdriverIO如何通过 Appium/WebdriverIO 更改 iOS 滑块值
【发布时间】:2020-07-09 14:57:02
【问题描述】:

我正在使用 Appium 和 WebdriverIO 测试我的 React Native 应用程序。难以更改滑块值。

通常在 XCUITest 中,我可以使用以下代码轻松实现此目的:

app.sliders["slider-red"].adjust(toNormalizedSliderPosition: 0)

如何在 Appium/WebdriverIO 中做等价的?我在某处读到我应该调用 sendKeys()。我尝试了以下方法:

$('~slider-red').sendKeys(['0']);

但它给了我以下错误:

元素状态无效:Error Domain=com.facebook.WebDriverAgent Code=1“屏幕键盘必须存在才能发送密钥”

看起来 sendKeys 是用于输入字段,而不是用于滑块!

【问题讨论】:

  • 您可能还想尝试其他选项。 github.com/webdriverio/webdriverio/issues/213
  • browser.setValue('~slider-red', 0); 给出此错误:TypeError: browser.setValue is not a function - 可能是因为我不在浏览器上下文中,我正在尝试测试原生 iOS 小部件。
  • 另一种解决方案看起来像是纯粹的浏览器。无论如何,我尝试了它的第一步 - browser.moveTo(100, 100);,它再次给了我一个错误:TypeError: browser.moveTo is not a function。我什至在浏览器上下文中尝试了这个语句,它仍然给我同样的错误!想知道我使用的样板是否不允许这样做:appium-boilerplate

标签: ios react-native appium webdriver-io xcuitest


【解决方案1】:

您可以尝试使用 Appium 为运行非 W3C 标准命令提供的移动手势。在你的情况下,它是mobile: selectPickerWheelValue 命令,更多细节here

const elementId = $(pickerwheel_locator).elementId
browser.execute('mobile: selectPickerWheelValue',
        {
            'order': 'next',
            'offset': 0.15,
            'element': elemId
        });

据我记忆,它是这样工作的

【讨论】:

  • 谢谢,@dmie。你的语法非常接近。在 WebdriverIO 中,我可以简单地执行 $('~slider-red').elementId 但是在此调用 browser.execute() 生成此错误之后:“无效参数:该元素应为有效的 Picker Wheel 控件。而是给出了 'XCUIElementTypeSlider'”。我终于在 Appium repo 中将问题追溯到this issue。不幸的是,他们认为这是 Apple 的错误并且没有解决方案 :-(
猜你喜欢
  • 1970-01-01
  • 2018-12-31
  • 1970-01-01
  • 1970-01-01
  • 2020-10-07
  • 1970-01-01
  • 2019-02-26
  • 2020-07-22
  • 1970-01-01
相关资源
最近更新 更多