LambdaTest Community

Find answers, support, and inspiration from other users

Questions 2
LambdaTest Community

Enter “Enter key” in Appium Testing

How to send/press Enter key from soft keyboard in Appium in Android Automation testing? I tried several options, but none of them are working - instead of pressing the key, they are clearing the text entered in text area. Below is the code (in JAVA Language):

String app_package_name = "";

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName", "Nexus_5X_API_23");
capabilities.setCapability("platformVersion", "6.0");
capabilities.setCapability("appPackage", app_package_name);
capabilities.setCapability("appActivity", app_package_name + ".activity.StartupActivity_");

String url = "";
AndroidDriver driver = new AndroidDriver(new URL(url), capabilities);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

By password = + "et_password");
WebElement enterPassword = driver.findElement(password);;

driver.getKeyboard().sendKeys(Keys.ENTER); // THIS IS NOT WORKING.
driver.getKeyboard().sendKeys(Keys.RETURN); // THIS IS ALSO NOT WORKING.
driver.pressKeyCode(AndroidKeyCode.ENTER); // THIS IS ALSO NOT WORKING.
driver.pressKeyCode(AndroidKeyCode.KEYCODE_NUMPAD_ENTER); // SAME HERE.
enterPassword.sendKeys(Keys.ENTER); // SAME HERE.

Please if anyone can help me achieve it?

Up Vote Down Vote 0 Votes
Posted one month ago

Answers 2

I was able to resolve this with this code:


Hope this helps.

Up Vote Down Vote 0 Votes
Posted 12 days ago

I am also facing this problem, but I have the code as:


If I understand correctly, the array allows you to run multiple key strokes at the same time like: cmd + a

Up Vote Down Vote 0 Votes
Posted 12 days ago
2 Answers
one month ago