3
votes

I am using appium to automate android application. In that, unable to perform sendkeys() on text fields for the below case: Clicking on Add Customer option. A new page is opened. I am trying to enter values in the text fields. I was able to find the text fields on the page using xpath. And I was able to click at the text fields. But When I execute sendkeys(), it is failing. Refer the below screenshots.

Link:1-Before adding customer(page-1) enter image description here

Link:2-Add customer-New page opened(page-2) and trying to enter details

enter image description here Link:3-After closing the page opened(page-2) and landing on page-1 enter image description here

5
Testcase is not failing for the above case.I connected a real device using USB cable. Using inspector, i found and clicked the particular element. When I type text and press sendkeys, text entered is not showing on device. Any suggestions? - sathiya
Is it possible to use sendkeyEvent to enter text using the andriod keyboard. If yes,can someone provide me an example - sathiya

5 Answers

2
votes

I can send keys to the android text field, by typing on android keyboard with AppiumDriver.sendKeyEvent(int key):

driver.findElement(locator).click();
driver.sendKeyEvent(29); // android key event code for letter 'a', look up key code at 
                         // android.view.KeyEvent library
driver.hideKeyboard();

You can use a loop to send all characters of your string using the android key board this way. Either use android.view.KeyEvent or convert character to key code (int) yourself

1
votes

it can be done using Action class

Actions action = new Actions(driver);
action.sendKeys("iphone").perform();
0
votes

Try sending a .Click() event to the element first so that the keyboard pops up (might have to put in a sleep for a second or two to give it time to draw on screen). Then try the sendKeys() method. This worked for me.

If that still doesn't work, another alternative is to use the adb. The following command will send text to the currently active element.

adb shell input text "<your string>"
0
votes

The easiest way is to take the textfields as a list and then pass the values individually. In your case i guess the code will be like:

driver.findElements(By.tagname("textfield")).get(1).sendkeys("xyz");
driver.findElements(By.tagname("textfield")).get(2).sendkeys("abc");

this worked for me well in android emulator and in device too.

0
votes

I can enter text or send keys to an android app text box using the code below:

driver.findElement(By.id("com.example.app-package:id/edt_first_name")).sendKeys("Poras");

You can find element id using android uiautomatorviewer see how to use here Can we find element by ID in appium Hope this would help you.