sathiya
sathiya

Reputation: 261

Sendkeys fails on android appium driver

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

Upvotes: 3

Views: 22366

Answers (5)

Anuj Bansal
Anuj Bansal

Reputation: 137

it can be done using Action class

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

Upvotes: 1

thangtran3112
thangtran3112

Reputation: 76

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

Upvotes: 2

Poras Bhardwaj
Poras Bhardwaj

Reputation: 1123

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.

Upvotes: 0

Vignesh
Vignesh

Reputation: 165

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.

Upvotes: 0

jcoopsco
jcoopsco

Reputation: 1

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>"

Upvotes: 0

Related Questions