React Native + Appium iOS TextInput.clear()



以下是我在Android上使用React Native中的Appium清除输入的代码:

driver.elementByAccessibilityId(inputName)
.then(input => input.click()
.then(() => input.clear()))

input.click()的存在是因为input.clear()在Android中似乎没有选择文本字段;此解决方法在Android上运行良好。

然而,input.click()在iOS上似乎没有任何作用。有人找到解决办法吗?

以下是我的解决方法:发送与TextInput中的字符一样多的退格。

不幸的是,由于这个问题,您必须知道TextInput中的文本是什么。如果有人想使用它,这是我的完整代码:

import {Platform} from 'react-native';
/**
* @param {string} inputName Name of element
* @param {string} value Value previously in the input, used by iOS.
* @returns {() => Promise}
*/
function clearInput(inputName, value) {
if (Platform.OS === 'android') {
return () => driver.elementByAccessibilityId(inputName)
.then(input => input.click()
.then(() => input.clear()))
.then(() => driver.hideDeviceKeyboard());
}
else {
return () => driver.elementByAccessibilityId(inputName)
.then(input => input.type('b'.repeat(value.length)))
.then(() => driver.hideDeviceKeyboard());
}
}

不过,我仍然想知道在iOS中是否有办法做到这一点,或者这只是Appium的一个错误。

最新更新