9

I'm trying (for too long...) to get appium working with react native, but can't seem to find any element.

I'm using an emulator, Nexus 6, android 6.0, ubuntu, appium 1.6.0, RN 0.39.2.

I'm trying to get the most basic example to work:

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

// spec.js
// ... some setup ...
      driver
        .elementByAccessibilityId('foo')
          .click()

and I'm getting...

      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.

I also tried setting: <Text accessible accessibilityLabel={ 'foo' }>foo</Text>

same response ...

any ideas?

Shining Love Star
  • 5,734
  • 5
  • 39
  • 49
  • How would you do this if you have a React-Native slideOutMenu and you want to tap one of the slideOutMenu options. Especially when the slide out menu covers only 50% of the screen behind it. AccessibilityInspector for XCODE sees the slideout menu but appium accessibilty inspector for android and ios doesn't even see the slide out menu. – duncwa Apr 19 '17 at 01:20
  • Refer this for the answer to find RN elements for appium :https://stackoverflow.com/questions/33937898/accessing-react-elements-using-appium-for-automation/57667701#57667701 or https://stackoverflow.com/questions/57460336/how-to-find-element-from-react-native-app-using-appium-react-native-appium/57864424#57864424 – Saif Siddiqui Sep 10 '19 at 05:20

1 Answers1

6

I ended up using this solution:

<Text accessibilityLabel={ 'FOO' } testID={ 'FOO' }>some stuff here</Text>

and then in the test:

driver
  .elementByAccessibilityId('FOO')

Credit goes to @jonesdar for pointing that out here

Shining Love Star
  • 5,734
  • 5
  • 39
  • 49
  • 1
    setting accessibilityLabel works with Android Emulator. But element cannot be found on real device connected with USB (with deployed Release build) – sytolk Oct 20 '17 at 15:13
  • 2
    Hack with `accessibilityLabel` instead of `testID` on Android is not actual since react-native@0.65.x!!! See changelog: https://github.com/react-native-community/releases/blob/master/CHANGELOG.md#android-specific-9 ; Commit: https://github.com/facebook/react-native/commit/381fb395ad9d2d48717a5d082aaedbecdd804554 ; – DAVID _ Oct 06 '21 at 23:29