This site is in read only mode. Please continue to browse, but replying, likes, and other actions are disabled for now.
15 / 15
Feb 2019

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.

  • created

    Mar '15
  • last reply

    Feb '19
  • 14

    replies

  • 22.7k

    views

  • 10

    users

  • 7

    likes

  • 2

    links

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.click();
element.sendKeys("your text"+"\n")

Hope it work

1 year later

For me it was working fine

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

2 months later

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

1 year later

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 = By.id2(app_package_name_with_id + “et_password”);
WebElement enterPassword = driver.findElement(password);
enterPassword.sendKeys(“12345”);

6 months later
WebElement ele = driver.findElement(By.id("co.nworks.leaveapp:id/edt_time"));
					ele.sendKeys("8.30");

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

6 months later

@Venkatesh_Akula
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(By.id(“com.google.android.apps.messaging:id/recipient_text_view”));

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){
element.click();
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));
}
com-resize

@harshitj

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.

@harshitj

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.

@harshitj

Please help me to understand only this line of code:

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

Please reply early if possible.

6 months later