How to click Enter after entering some text

I am using Android emulator to test an application.

I am able to enter text in a text a text field, and trying to enter click enter by following code:

element.sendKeys("Some text");
element.sendKeys(Keys.ENTER); also tried with Keys.RETURN // both of these deleting the text which i entered in the text field rather than clicking enter.

So i tried to simulate this by using Actions class like below:

Actions action=new Actions(driver)
action.sendKeys("Some text").sendKeys(Keys.ENTER).build().perform();//Here i am getting an exception saying it is not yet implemented.

So can anyone help me to provide a solution to the problem.


Not sure if you have named the web element/mobile element as driver. There isn’t any sendKeys() method with driver.
And for sending the enter key you have to use key event i.e. driver.sendKeyEvent(Keys.ENTER);

If that does not work you can try;
element.sendKeys("your text"+"\n")

Hope it work


For me it was working fine [quote=“pr4bh4sh, post:2, topic:3136”]
element.sendKeys(“your text”+"\n")

but it suddently stopped working since last Monday. Anybody as succeded recently with this topic?

You can try this code:
driver.pressKeyCode(AndroidKeyCode.KEYCODE_NUMPAD_ENTER );
since “sendkeycode” is not available now and “enter in number pad” is working.


Any of the above tricks are not working with me. Any other option?

Below is my code to enter password and then enter key.
By password = + “et_password”);
WebElement enterPassword = driver.findElement(password);

WebElement ele = driver.findElement("co.nworks.leaveapp:id/edt_time"));

After this ,I want to press ok/enter. please suggest.above solutions not working for me. Thanks in advance

HI Venkatesh,

I need to know how can we can enter two numbers in same text box, but one by one and not all together.

Below is the screenshot of the text box in which I want to enter the numbers:

Please refer the attached image to get more clear idea about my query:

After entering the one number in To: textbox I will click on the icon mark in yellow, after clicking on the yellow icon the cursor will appear on the To: textbox after the first number which was entered previously.
The Cursor is indicated in the image using the orange line.

When I try to enter another number after the cursor, it will overlap the previous number and the previous number would be erased so please help me to solve this issue

No idea, I haven’t came across scenario like this. Try to do the same steps manually and see what’s happening and based on that try to modify your code

@Sagar_Khanvilkar : You can create custom method for this.

Start appium as : appium --relaxed-security

This will allow you to execute adb shell input text ‘ANY STRING’ command from your script.

Find the element locator for Recipient text box.
Example :MobileElement element=driver.findElement(“”));

Below is the Custom Method which tap on recipient(To text box) and enter multiple String(Contact Numbers) one after another

public void enterTextMethod(MobileElement element,String inputText){;
List enterText = Arrays.asList(“text”, inputText);
Map<String, Object> cmd = ImmutableMap
.of(“command”, “input”, “args”, enterText);
driver.executeScript(“mobile: shell”, cmd);
((AndroidDriver) driver).pressKey(new KeyEvent(AndroidKey.ENTER));



Thank you so much for your response.

Actually I am not pro-efficient with Java so will you please explain me the below lines of code:

List enterText = Arrays.asList(“text”, input);

Map<String, Object> cmd = ImmutableMap

.of(“command”, “input”, “args”, enterText);

driver.executeScript(“mobile: shell”, cmd);

I know it is bit difficult to explain through writing but it would be great if you will do so.

Thank you once again.

  1. driver.executeScript(“mobile: shell”, cmd);
    mobile :shell will execute as adb shell commands with arguments. Example : adb shell input text '13444’
    input is the adb shell command used to perform some operation and text is the argument which decide the operation will enter data in the textfield. ‘13444’ is the data passed to the textfield.

2.Map<String, Object> cmd = ImmutableMap
.of(“command”, “input”, “args”, enterText);
Now cmd here contain two key-value. Input
is the value for key ‘command’. In similar way args keys contains command arguments.


Thank you so much harshit, it was really helpful, but still i am not 100% clear, sorry for that.

It would be great if you share the sample code for more clear picture.

Thank you in advance.

Actually i am confuse that from where these “command”, “input”, “args”, enterText variables are coming from.


Please help me to understand only this line of code:

((AndroidDriver) driver).pressKey(new KeyEvent(AndroidKey.ENTER));

Please reply early if possible.

The above line of code is used to press Enter Key.

You can also press particular key using KeyEvents on android.

Read More on Key Events :

it works well with me… thanks

Responding to the original question:

This solution in JavaScript using wd worked for me:

return driver.waitForElementById(<elementId>).type(<text to type>).click().execute( "mobile: performEditorAction", { "action": "search" } );

This allowed me to find a text field, input some text, and submit a search command (same as clicking the search icon in the keyboard). Of course, you have to replace <elementId> and <text to type> with the proper values. See for details on “mobile: performEditorAction”.

Works for me on Ruby and Appium and ios and android devices,same way you described here


element.sendKeys(“your text”+"\n")
this worked for me

How it is can be implemented with Python syntax? Method driver.press_button(’\n’) is not worked (I do it for iOS platform).

Anyone can help me, please?

the python bindings I have don’t let you express that.
webelement = driver.find_element_by_xpath("//*[@text=‘Login’]")