appiumjava-client

Keyboard enter key not working in appium java-client 6.0.0-BETA2


i'm trying automate the search scenario, i mean pass one text to input field and hit enter button of keyboard.

so far, i tried below:

  1. ((AndroidDriver)driver).pressKeyCode(AndroidKeyCode.ENTER);
  2. driver.getKeyboard().sendKeys(Keys.ENTER);
  3. driver.press_keycode(66)
  4.     Robot robot;
        try {
            robot = new Robot();
             robot.keyPress(KeyEvent.VK_ENTER);
             robot.keyRelease(KeyEvent.VK_ENTER);
        } catch (AWTException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

and, i'm using java-client 6.0.0-BETA2

can anyone help in this?

Screenshot: enter image description here


Solution

  • Try following code. It must work:

    import io.appium.java_client.MobileElement;
    import io.appium.java_client.android.AndroidDriver;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import io.appium.java_client.android.nativekey.AndroidKey;
    import io.appium.java_client.android.nativekey.KeyEvent;
    
    ((AndroidDriver<MobileElement>) driver).pressKey(new KeyEvent(AndroidKey.ENTER));
    

    Before using enter key, you must first click on text input field.