Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React native + Appium, how to find an element

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?

like image 990
goldylucks Avatar asked Jan 04 '17 17:01

goldylucks


People also ask

How do I find an element in Appium?

Finding elements using the ID is, by far the simplest technique. Each element has a unique ID assigned to it that helps in identifying and interacting with it. Appium has a Native element identifier for Android and iOS. resource-id is used as an element identifier for Android and name is used for iOS.

What is Appium inspector?

Appium Inspector allows you to perform tests on real mobile devices in app testing scenarios, such as writing mobile test scripts with Appium Inspector to identify objects easily. This has provided ample reasons for teams to use real Android and iOS devices to perform testing.

How do you click on an image in Appium?

In order to tap on a found image element, Appium has to use one of its touch action strategies. The available strategies are the W3C Actions API, or the older MJSONWP TouchActions API. Stick to the default unless the driver you are using does not support the W3C Actions API for some reason.


1 Answers

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

like image 85
goldylucks Avatar answered Nov 14 '22 22:11

goldylucks