Unable to tap on Search on android keyboard using pressKeyCode(int) method

I am a beginner in Appium automation. The application I am testing, have this scenario where I need to tap on Search button from the native keyboard. I have tried with pressKeyCode method but get this error The method pressKeyCode(int) is undefined for the type WebElement

I am using the following Appium 1.4.16.1 with Java client 5.0.0-BETA8 Selenium 3.4.0

I don’t know what I am doing wrong. I have tried with earlier java client for appium as well but nothing have worked so far. Also, if there is a work around other than the pressKeyCode to do this?

@mbasit

  1. update appium at least to 1.6.5
  2. add test code you tried

This is the excerpt from my test code
driver.findElement(By.name(“Search Job Guides”)).sendKeys(“guide”);
driver.pressKeyCode(66);

I am now updating appium. Lets see if that works.

@mbasit how about:

 ((AndroidDriver) driver).pressKeyCode(AndroidKeyCode.KEYCODE_SEARCH); //int KEYCODE_SEARCH = 84;

I have tried both
Updated appium version to 1.6.5
Also tried with this piece of code, still getting the same error “The method pressKeyCode(int) is undefined for the type AndroidDriver”

Btw, really appreciate your replies.

@mbasit update java client to at least 5.0.1

Tried that as well,
Still not working.

@mbasit not working what? you have “undefined” or you tried code and no result?

Sorry I meant still getting the same undefined method error.

@mbasit can you share your code at https://gist.github.com/ ?

Sure

Btw, I have tried with both AndroidDriver and WebDriver. Got the same error for both.

@mbasit i commented your gist with correct imports. all should work with you now.

Hey,

Yes the code is working now. Thanks a ton for that but I am still unable to tap on the Search key. I have tried to tap on other keys and it works perfectly fine but it does not tap on the search key.

@mbasit tried and it was worked below with mine app:

        ((AndroidDriver) driver).pressKeyCode(AndroidKeyCode.ENTER);

@Aleksei @mbasit

I’m having the same problem. The code below does not seem to do anything against genymotion with soft keyboard enabled.

androidDriver.pressKeyCode(AndroidKeyCode.KEYCODE_SEARCH);

It would be great if someone who has workaround would share their solution.

I also faced same issue, so as a solution i used below code:

TouchAction touchAction=new TouchAction(driver);
touchAction.tap(xPosition, yPosition).perform();

tap at paritcular coordinates. Using Appium inspector you can find the coordinates.

How to move next screen by clicking on arrow button present on keyboard.

Please find image

I have the same issue enter or search keys do not work on appium (Appium latest version, using real device)
driver.pressKeyCode(AndroidKeyCode.KEYCODE_ENTER);
I also tried keycode=66 that does not work either .

Any ideas? Thanks