摩卡无法在输入字段中找到 ID - react-native

Mocha can't find the ID inside a input field - react-native

我正在尝试通过 .text(); 获取输入的文本;来自 Selenium 的方法。但是每次我尝试获取元素时,它都会输出找不到相关 ID。

(我正在使用来自 nativebase 的输入,但我已经尝试使用 textinput 本机组件对其进行测试)

                      <Form>
                            <Item
                                testID='input_nomePaciente_formPacientes'
                                stackedLabel>
                                <Label style={styles.label}>Nome</Label>
                                <Input value={this.state.paciente.nome.toUpperCase()}
                                    style={styles.inputForm}
                                    testID='input_testID'
                                    autoCorrect={false}
                                    keyboardType={(Platform.OS === 'android') ? 'visible-password' : ''}
                                    autoCapitalize='none'
                                    onChangeText={(text) => this._updateItem('nome', text, 0)} />
                            </Item>

我可以使用 sendKeys() 与元素交互;并点击();通过 Item testID,但我无法与输入中的任何内容进行交互。我也无法通过Item testID获取该字段的值。

这是我尝试获取输出的方式:


let testID = await driver.elementByAccessibilityId("input_testID");
            let testIDValue = await testID.text();

            console.warn(testIDValue);

原来 mocha/selenium 找不到导入的 nativebase 组件。尝试通过原生组件获取输入,结果还不错。

这非常有效:

<Label style={{ marginLeft: 10 }}>Login</Label>
      <TextInput // react-native input component
          autoCapitalize='none'
          testID='input_login'
          editable={true}
          autoCorrect={false}
          keyboardType={(Platform.OS === 'android') ? 'visible-password' : ''}
          onChangeText={(item) => this.setState({ login: item })}
          value={this.state.login} 
       />

即使你用手指交叉也行不通:

<Form>
      <Item
           testID='input_nomePaciente_formPacientes'
           stackedLabel>
           <Label style={styles.label}>Nome</Label>
           <Input // nativebase input component
              value={this.state.paciente.nome.toUpperCase()}
              style={styles.inputForm}
              testID='input_testID'
              autoCorrect={false}
              keyboardType={(Platform.OS === 'android') ? 'visible-password' : ''}
              autoCapitalize='none'
              onChangeText={(text) => this._updateItem('nome', text, 0)} />
      </Item>
</Form>