Android - sendKeys performs long-press somehow

I have a username textfield on an Android app. If a user long-presses on the textfield, a menu pops up. If a user lightly taps inside the textfield, then the user can enter the username.

If I use sendKeys, it somehow is interpreted as long-press which I do NOT want. How do I avoid triggering long-pressing from sendKeys?

Hi @Mayu_Kataoka,

Just perform click on before you enter sendKeys in Text Field.
element.click();
element.clear(); //(This statement is not mandatory)
element.sendKeys(“text”);

have a try, will get resolved.

Thanks,
Bhaskar.

Followed the steps. Still doing long-press instead.

Interesting use case, @isaac is there a way to simulate that?

Maybe the app would need to be modified so that once the user has started typing the menu does not show anymore.

Worked around this sendKeys problem by:

emailField.click();
Process p = Runtime.getRuntime().exec("/Users/username/Library/Android/sdk/platform-tools/adb -s emulator-5554 shell input text [email protected]");

Hope this helps if anyone else is having the same issue…

1 Like

Hi All

We ran into a similar issue with one of the PID (passcode) fields in our mobile app and we were able to sort that with a click and using the pressKeyCode method… Hope it helps others too :slight_smile:

driver.findElement(By.id("au.org.silverchain.comcare:id/pinEntry")).click( );

driver.pressKeyCode(AndroidKeyCode.KEYCODE_7 );