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


#1

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?


#2

@mbasit

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

#3

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.


#4

@mbasit how about:

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

#5

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”


#6

Btw, really appreciate your replies.


#7

@mbasit update java client to at least 5.0.1


#8

Tried that as well,
Still not working.


#9

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


#10

Sorry I meant still getting the same undefined method error.


#11

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


#12

Sure

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


#13

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


#14

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.


#15

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

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

#16

@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.


#17

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.


#18

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

Please find image


#19

#20

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