React Native + Appium,如何找到元素

gol*_*cks 6 android appium react-native

我试图(太长时间了...)使appium与本机反应,但似乎找不到任何元素。

我正在使用模拟器,Nexus 6,android 6.0,ubuntu,appium 1.6.0和RN 0.39.2。

我正在尝试使最基本的示例工作:

// foo.js
render () {
  return (
    <Text>foo</Text>
  )
}

// spec.js
// ... some setup ...
      driver
        .elementByAccessibilityId('foo')
          .click()
Run Code Online (Sandbox Code Playgroud)

而我得到...

      1) should be able to find 'Buttons' and click it


  0 passing (13s)
  1 failing

  1) Android find and click should be able to find 'Buttons' and click it:
     Error: [elementByAccessibilityId("foo")] Error response status: 7, , NoSuchElement - An element could not be located on the page using the given search parameters. Selenium error: An element could not be located on the page using the given search parameters.
Run Code Online (Sandbox Code Playgroud)

我也尝试设置: <Text accessible accessibilityLabel={ 'foo' }>foo</Text>

相同的反应...

有任何想法吗?

gol*_*cks 5

我最终使用了这个解决方案:

<Text accessibilityLabel={ 'FOO' } testID={ 'FOO' }>some stuff here</Text>
Run Code Online (Sandbox Code Playgroud)

然后在测试中:

driver
  .elementByAccessibilityId('FOO')
Run Code Online (Sandbox Code Playgroud)

感谢@jonesdar在此处指出这一点

  • 自react-native@0.65.x以来,在Android上使用“accessibilityLabel”而不是“testID”进行黑客攻击是不实际的!请参阅更改日志:https://github.com/react-native-community/releases/blob/master/CHANGELOG.md#android-specific-9;提交:https://github.com/facebook/react-native/commit/381fb395ad9d2d48717a5d082aaedbecdd804554; (2认同)