How to handle native android keyboard using appium


#21

Except what rakesh said in the above thread(as i cannot force developer to write extra code and developers are not accessible for me)

I tried all the ways specified in this thread, but didnt help. Can someone help me here?

element.sendKeys(strValue+"\n"); - entering the value but soon after navigating to home screen.

element.sendKeys(strValue);
String command = “adb -s input keyevent KEYCODE_SEARCH”;
** try {**
** Process result = Runtime.getRuntime().exec(command);**
** } catch (IOException e) {**
** // TODO Auto-generated catch block**
** e.printStackTrace();**
** }**
enter the value but didnt click on Search button.

element.sendKeys(strValue);
driver.sendKeyEvent(AndroidKeyCode.ENTER);
Enter the value and bringing back to home screen.

Also tried with Keyevent codes 84 and 66, but didnt help.

Can someone let me know any other soluctions


#22

Hi UD

i tried all solution nothing worked for me… i have wasted lots of time trying to find solution without approaching developers, but i did’t do any progress …

my suggestion is ask you develop to add click Listers then it should work

RK


#23

Ohhhhh… the problem for me is, the app developers are 3rd party vendors and we dont have any access to approach them.


#24

@UD
have you been able to get this problem solved?


#25

@UD the only workaround that I found is to use a third party keyboard (GO Keyboard works for me) and then send key event 66. Works as expected. Maybe if you reverse engineer GO Keyboard implementation you can get more insight on how to make it work without a third party keyboard. Cheers!


#26

driver.pressKeyCode(66);
//This is to press “Enter” from keyboard

https://developer.android.com/reference/android/view/KeyEvent.html#KEYCODE_TAB


#27

The driver.pressKeyCode(66); method doesn’t work for me. The only other solution I have seen is to tap the button based on coordinates. Although it would work it would be awful when trying to support multiple devices.

Has there been any progress on this topic? This feature is fairly critical for the work that I am doing. If anyone has a solution to this it would be greatly appreciated.


#28

Hello, Did you have added jars of java client jar and android jar?


#29

guys i want to add that Appium driver now has key press code in its API


#30

How can we handle enter key on custom numeric keyboard in Android?


#31

You can try it for maven project:
((AndroidDriver)driver).pressKeyCode(66);


#32

I am using Python 3.6 + Appium V1.6.5
Try the following:

Set the following two lines to your desired_caps.
desired_caps[‘unicodeKeyboard’] = True
desired_caps[‘resetKeyboard’] = True

Then use keycode 66. it works for me.
driver.press_keycode(66)


#33

I’m using:
io.appium -> 6.1.0
selenium -> 3.13.0
guava -> 24.0-jre

When I use : ((AndroidDriver)driver).pressKeyCode(67);
I get the following error message with pressKeyCode instruction striked-on : The method pressKeyCode(int) from the type PressesKey is deprecated


#34

With 6.1.0, use this way to press a particular key :
((AndroidDriver) driver).pressKey(new KeyEvent(AndroidKey.ENTER));


#35

@harshitj :

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

  1. pressKey gives error:
    The method pressKey(io.appium.java_client.android.nativekey.KeyEvent) in the type PressesKey is not applicable for the arguments (java.awt.event.KeyEvent)
    2 quick fixes available:
    Change to longPressKey()
    Change to pressKeyCode()

  2. (new KeyEvent(AndroidKey.ENTER) gives error: The constructor KeyEvent(AndroidKey) is undefined

  3. KeyEvent is striked.

  4. On changing pressKey to pressKeyCode, I’m getting error: The method pressKeyCode(int) in the type PressesKey is not applicable for the arguments (KeyEvent)


#36

You have included wrong import ‘KeyEvent’.

Remove : import java.awt.event.KeyEvent;

Add these import only :
import io.appium.java_client.android.nativekey.KeyEvent;
import io.appium.java_client.android.nativekey.AndroidKey;


#37

Hi,
I tried with
AndroidDriver driver;
driver.pressKeyCode(66);

It worked for me. Hope it helps you for Android Keyboard Events.
Enter key.
Constant Value: 66


#38

@harshitj, @Sankar_G : Thanks for your inputs.
Presently I have some other business related roadblock, so I’ll update you after some days on what is working.


#39

Thanks a lot! It helps me!


#40

it worked…, really cool… thanks