I had trouble with this too. A main issue I found was that in order to delete the area by pressing the delete key was that it needed to tap at the end of the line. This works for me:
public void clearTextField(WebElement element) {
double x = element.getLocation().getX() + element.getSize().width - 5;
double y = element.getLocation().getY() + ((double) element.getSize().height / 3);
preciseTap(x, y, 0.1, 1);
while (!element.getText().isEmpty()) {
pressDeleteKey();
}
}
public void preciseTap(double x, double y, double duration, int touchCount) {
JavascriptExecutor js = (JavascriptExecutor) driver;
HashMap<String, Double> tapObject = new HashMap<String, Double>();
tapObject.put("x", x);
tapObject.put("y", y);
tapObject.put("touchCount", (double)touchCount);
tapObject.put("duration", duration);
js.executeScript("mobile: tap", tapObject);
}
public void pressDeleteKey() {
HashMap swipeObject = new HashMap();
swipeObject.put("keycode", 67);
((JavascriptExecutor) driver).executeScript("mobile: keyevent", swipeObject);
}
It is a lot slower than just clearing it all out but I have not figured out how to do this yet. Would be ideal to double tap or tap and hold until everything is selected.