Hello, recently with the latest Appium we cannot anymore use the .clear() for clearing the text field. What can we use as an alternative since the below code does not work as well
in some cases we need to use different logic. e.g. with one field of our app I have below.
see with android tried 3 different ways. one works better exactly with on this screen.
EACH command search for element first and then makes clear or sendKeys.
@iOSXCUITFindBy(id = "generated_AmountTextField")
@AndroidFindBy(className = "android.widget.EditText")
private WebElement amountInput;
if (isIOS) {
Assert.assertTrue(clearInput(amountInput), createAssertionLog("FAILED clear 'amountInput'"));
Assert.assertTrue(setValue(amountInput, amount), createAssertionLog("FAILED"));
} else {
Assert.assertTrue(tap(amountInput), createAssertionLog("FAILED"));
Assert.assertTrue(clearInput(amountInput), createAssertionLog("FAILED clear 'amountInput'"));
// double for sure
sleep(250);
for (int i = 0; i < 4; i++)
pressKey_Android(AndroidKey.DEL);
sleep(250);
//*
// does not work well here
// Assert.assertTrue(setValue(amountInput, amount), createAssertionLog("FAILED"));
//*/
// driver.executeScript("mobile: type", ImmutableMap.of("text", amount));
sendTextToKeyboard(amount);
// hideKeyboard();
}
@Step("Press Key Android")
public boolean pressKey_Android(AndroidKey Key) {
Logger.log();
try {
((AndroidDriver) driver).pressKey(new KeyEvent(Key));
return true;
} catch (Exception ex) {
return false;
}
return false;
}
@Step("Send text to keyboard {text}")
protected boolean sendTextToKeyboard(String text) {
Logger.log("text: '" + text + "'");
try {
new Actions(driver).sendKeys(text).perform();
// deprecated
// driver.getKeyboard().sendKeys(text);
return true;
} catch (Exception e) {
Logger.log();
e.printStackTrace();
return false;
}
}