How to Clear multiple masked (password) text characters in appium?

I am trying to clear already present text from the Password textfield. I am able to use .clear() to delete all the already existing text from the text box, but since password is a masked textfield, .clear() doesnot remove all fields. It just deletes the first 2 characters from the existing text and appends the new text to the remaining characters. Can any one please help me solve this problem???

You alternatively can do a method with press_keycode 67 #delete key

for example you collect the current text size on your element and you send that amount of delete keys with the element previously selected.

public void clear(String locatorType, String locator, long waitSeconds)
WebElement we = getElementWhenPresent(getByLocator(locatorType, locator), waitSeconds);
String text = we.getText();
int maxChars = text.length();
for (int i = 0; i < maxChars; i++)


@Sruthi, I tried doing that. But since password is a masked field, it is not possible to get the length of its text. Even getText() returns null for the password field.

Why can’t you set the maxChars manually (int maxChars = 8)based on the length of the text, since you know which field you are testing and make the function specific to clearPassword() :wink: