3

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

sathiya
  • 279
  • 1
  • 5
  • 17
  • 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 Sep 01 '14 at 15:06
  • Is it possible to use sendkeyEvent to enter text using the andriod keyboard. If yes,can someone provide me an example – sathiya Sep 04 '14 at 15:11

5 Answers5

2

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

bhdrk
  • 3,415
  • 26
  • 20
thangtran3112
  • 76
  • 1
  • 4
  • I tried the same as you suggested. But still it is not working. `driver.findElement(By.xpath("//android.widget.ScrollView[1]/android.widget.EditText[1]")).click(); ((AppiumDriver) driver).sendKeyEvent(29); ((AppiumDriver) driver).hideKeyboard();`Any suggestions? – sathiya Sep 12 '14 at 13:15
  • `WebElement name=driver.findElement(By.xpath("//android.widget.ScrollView[1]/android.widget.EditText[1]")); name.click(); ((AppiumDriver) name).sendKeyEvent(29);' **I tried like this as well. Now I am getting error:io.appium.java_client.MobileElement cannot be cast to io.appium.java_client.AppiumDriver** – sathiya Sep 12 '14 at 14:07
1

it can be done using Action class

Actions action = new Actions(driver);
action.sendKeys("iphone").perform();
Anuj Bansal
  • 117
  • 5
0

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>"
  • I have already tried this-./adb shell input text Hello. It is working in other pages. But not in the above the page that i have attached. – sathiya Sep 12 '14 at 13:26
  • I have downloaded appium 1.2.2 Now sendkeys is working. **But When i use sendkeys, all the values are getting entered in the last field. Once the testcases is executed, i am getting error stating no such element found for the last field.** Any suggestions – sathiya Sep 15 '14 at 19:50
0

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.

Vignesh
  • 165
  • 4
  • 15
0

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.

Community
  • 1
  • 1
Poras Bhardwaj
  • 1,073
  • 1
  • 15
  • 33