React native + Appium,如何查找元素

时间:2017-01-04 17:22:55

标签: android react-native appium

我正在尝试(太长时间......)让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()

我正在......

      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.

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

同样的反应......

任何想法?

2 个答案:

答案 0 :(得分:2)

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

# import usefull libraries
import numpy as np
import cv2

# Set global parameters
RED = 0
GREEN = 1
BLUE = 2

# Load the image
img_color = cv2.imread("fruits.jpg", flags=cv2.IMREAD_COLOR)

# Filter the image by desired color
img_color_filtered = np.asarray([y[RED] for x in img_color for y in x]).reshape((img_color.shape[:2]))

然后在测试中:

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

@ jonesdar指向here

答案 1 :(得分:0)

尝试在文字上设置testID={'foo'}并使用.elementByName('foo'),不确定这是否仍然有效但值得一试。