LambdaTest Community

Find answers, support, and inspiration from other users

Questions 2
LambdaTest Community
Answered

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 = "abc.xyz.android";

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 = "http://127.0.0.1:4723/wd/hub";
AndroidDriver driver = new AndroidDriver(new URL(url), capabilities);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

By password = By.id(app_package_name_with_id + "et_password");
WebElement enterPassword = driver.findElement(password);
enterPassword.click();
driver.getKeyboard().sendKeys("12345");

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:

driver->getKeyboard()->pressKey(WebDriverKeys::TAB);
driver->getKeyboard()->pressKey(WebDriverKeys::ENTER);

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:

driver->getKeyboard()->sendKeys(array(Keys.TAB));
driver->getKeyboard()->sendKeys(array(Keys.TAB));

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
135 Views
2 Answers
one month ago