ken4ward
ken4ward

Reputation: 2296

Appium not working with numeric keyboard

I am trying to enter numbers in an edit field, though the field is focused Appium wasn't able to input the characters. I have tried it in multiple ways, all did not work.

Example 1:

driver.FindElementByXPath("field_to_fill").SendKeys("value");

Example 2:

_driver.PressKeyCode(AndroidKeyCode.KeycodeButton_8);

The field is EditText field, the Android platformVersion: 7.0, and I'm using C#.

Upvotes: 1

Views: 4869

Answers (2)

desertgirl
desertgirl

Reputation: 21

This is older, but maybe this will help someone in the future. I ran into this issue yesterday after the app under test changed from a qwerty keyboard to a number pad. (In Java) I was originally using driver.sendKeys(stringOfDigits), which broke with the number pad keyboard showing. Neither driver.setValue(stringOfDigits) nor driver.pressKey(new KeyEvent(AndroidKey.NUMPAD_0)); worked either.

I found that driver.pressKey(new KeyEvent(AndroidKey.DIGIT_0)); worked. Or in my case, I was inputting a set of numbers from a string, so I used a loop:

for(char c : stringOfDigits.toCharArray()) {
  driver.pressKey(new KeyEvent(AndroidKey.valueOf("DIGIT_" + c)));
}

I normally work with C#, but this project is in Java. Hopefully Appium is the same for both languages.

Upvotes: 2

Kovacic
Kovacic

Reputation: 1481

I had simmilar issue on java, so I used two methods for workaround:

1.method - tap on the textField() - get pageobject for UIAKeyboard, override numpad keyboard (fetch all buttons into page object) - used scripted method in pageobject to click on Number element. by name.

2.method - send keycodes (try using native driver AndroidDriver instead MobileDriver)

3. method

driver.sendkeyEvent(int key);

List Of Key codes:

a - z-> 29 - 54
"0" - "9"-> 7 - 16 
BACK BUTTON - 4, 
MENU BUTTON - 82 
UP-19, 
DOWN-20,
LEFT-21, 
IGHT-22 
SELECT (MIDDLE) BUTTON - 23 
SPACE - 62, 
SHIFT - 59,
ENTER - 66,
BACKSPACE - 67

or for newer version

driver.pressKeyCode(AndroidKeyCode.HOME);

4. method (didn't tested) with x,y co-ordinate for each number (0-9 & .) and used driver.tap method

Upvotes: 0

Related Questions