I am working on automation of mobile native app using Appium in Java language. I want to click on device Menu button.

Method 1:

 JavascriptExecutor js = (JavascriptExecutor) driver;
 js.executeScript("mobile: keyevent", 82);

tried but not working.

Method 2:-

HashMap swipeObject = new HashMap();
swipeObject.put("keycode", 82);
((JavascriptExecutor ) driver).executeScript("mobile: keyevent", swipeObject);


driver.execute_script("mobile: keyevent", {"keycode": 82})

this is not working,can any one help me on this.

  • You should use applium sendkey method , Like : AppiumDriver.sendKeyEvent(AndroidKeyCode.MENU) OR driver.getKeyboard().sendKeys(AndroidKeys.MENU); Feb 3, 2015 at 6:39
  • i am using webdriver..is it ok for it
    – RaMeSh
    Feb 3, 2015 at 6:41
  • Yes of course. It is ok with appium + webdriver. Feb 3, 2015 at 6:42
  • code is same which I have shared as comment. Once you confirm that it is working then sure i will post as answer. Feb 3, 2015 at 6:44
  • code is required for click device menu bar at top right.
    – RaMeSh
    Feb 3, 2015 at 6:47

2 Answers 2


Appium Java-client provides mechanism to Send a key event to the device. Please check the here for more details. So for latest appium java client, below code should work.

  • Can you please explain what trick does this do? Jul 13, 2016 at 3:29
  • I don't think it as trick, Appium Java-client provides mechanism to Send a key event to the device. Please check this...appium.github.io/java-client/io/appium/java_client/android/… Jul 13, 2016 at 3:35
  • Adding this explanation and the reference link to your answer would me more helpful for Narendra as well as other people having similar query! Some reason as to why this would work and why it is a better option over any other (if available) really helps!!! Jul 13, 2016 at 3:48

The simplest working solution is to use the KEYCODE KeyEvent:

adb shell input keyevent <KEYCODE_MENU>

Help - Android keycode

  • can you expand on why this is a good solution?
    – ECiurleo
    Jul 11, 2016 at 8:34
  • @Eciurleo - 1 This is shell command. 2 It will directly intended to communicate with device 3 Utility included in android sdk itself Due to above all, success percentage may increase than other methods. This was my criteria for simplest solution :) Jul 11, 2016 at 9:24
  • sounds good, can you add that into your answer using the edit? Most users find it helpful to include the logic and background as to why a solution is the preferred one rather than just giving a solution :)
    – ECiurleo
    Jul 11, 2016 at 14:32
  • sure @ECiurleo , but waiting to know if it works for RaMeSh Jul 19, 2016 at 13:30
  • people accept answers based on the answer itself, not the comments. The comments should be a mechanism to improve the answer only.
    – ECiurleo
    Jul 19, 2016 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.