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?
Before using
((AndroidDriver)driver).pressKeyCode(AndroidKeyCode.ENTER);
Set the following desired capabilities
capabilities.setCapability("unicodeKeyboard", "true");
capabilities.setCapability("resetKeyboard", "true");