trial999
trial999

Reputation: 1716

UIAutomator pressing Select All after textselection to clear text with spaces

I have got a text like "ABC XYZ"

//Below Code selects ABC and clears it and enter 123 , resulting in "123 XYZ"

editText.setText("123");

Is there a way I can select the entire string even if it has spaces in it.

Upvotes: 0

Views: 1349

Answers (3)

Sachin Gupta
Sachin Gupta

Reputation: 8358

You can use below workaround :

String text = editText.getText();
editText.clickBottomRight();
for (int i=0;i<text.length();i++) {
    UiDevice.getInstance().pressDelete();
}
editText.setText("123");

Upvotes: 3

JohnSmith
JohnSmith

Reputation: 96

Can't you try this instead, This will clear the editText box value and then set it.

editText.clearText();

editText.setText("123");

Upvotes: 0

user2469536
user2469536

Reputation: 1

This is the workaround I'm using:

editText.longClick();

pause for 50 ms:

//UiObject selectAll = new UiObject(new UiSelector().descriptionContains("Select all"));
selectAll.click();

pause for 250 ms:

//UiDevice dev = getInstance();
dev.pressKeyCode(KeyEvent.KEYCODE_DEL, 0);

You might want to play with pause.

Upvotes: -1

Related Questions