Undefined method `key_event' for Appium::Driver

I’m trying to open the Menu in Android phone with Appium and Ruby.
I’ve tried all functions (keyevent, key_event, with and without execute_script, ect…) I’ve found but it doesn’t work.
I have “undefined method `key_event’ for Appium::Driver”.
My entire code is below, can you help me ?
I really need this and I’ve tried fro days :frowning:
Thanks a lot !

require ‘rubygems’
require ‘watir-webdriver’
require ‘rspec’
require ‘appium_lib’

capabilities = {
caps: {
‘browserName’ => ‘Chrome’,
‘platformName’ => ‘Android’,
‘deviceName’ => ‘Android’
appium_lib: {
sauce_username: nil, # don’t run on Sauce
sauce_access_key: nil
@driver_appium = Appium::Driver.new(capabilities)
@driver = @driver_appium.start_driver
@browser = Watir::Browser.new @driver
@browser.driver.manage.timeouts.implicit_wait = 15


	@driver_appium.key_event 82

I’m sorry I can’t help fix the problem you report, but I can offer a workaround: system(‘adb shell input keyevent 82’)

Is it common practice to include the watir-webdriver gem when using appium with ruby?

key_event was renamed to press_keycode. Try this:

@driver_appium.press_keycode 82

Thanks, your workaround works great !

If I don’t put the watir-webdriver, I have this error:
“Test.rb:19:in `’: uninitialized constant Watir (NameError)”

When I try press_keycode, I don’t have the same “undefined method” error but I have this:
on appium log:
info: [debug] Proxied response received with status 404: “unknown command: session/a376795a01a6006c2de5b917e5122754/appium/device/press_keycode”
info: <-- POST /wd/hub/session/a376795a01a6006c2de5b917e5122754/appium/device/press_keycode 404 2.582 ms - 85

on Terminal logs:
/Users/elerouge/.rvm/gems/ruby-2.1.2/gems/selenium-webdriver-2.42.0/lib/selenium/webdriver/remote/http/common.rb:66:in create_response': unexpected response, code=404, content-type="text/plain" (Selenium::WebDriver::Error::WebDriverError) unknown command: session/a376795a01a6006c2de5b917e5122754/appium/device/press_keycode from /Users/elerouge/.rvm/gems/ruby-2.1.2/gems/selenium-webdriver-2.42.0/lib/selenium/webdriver/remote/http/default.rb:66:inrequest’
from /Users/elerouge/.rvm/gems/ruby-2.1.2/gems/selenium-webdriver-2.42.0/lib/selenium/webdriver/remote/http/common.rb:40:in call' from /Users/elerouge/.rvm/gems/ruby-2.1.2/gems/selenium-webdriver-2.42.0/lib/selenium/webdriver/remote/bridge.rb:634:inraw_execute’
from /Users/elerouge/.rvm/gems/ruby-2.1.2/gems/selenium-webdriver-2.42.0/lib/selenium/webdriver/remote/bridge.rb:612:in execute' from /Users/elerouge/.rvm/gems/ruby-2.1.2/gems/appium_lib-4.1.0/lib/appium_lib/device/device.rb:169:inpress_keycode’
from Test.rb:24:in `’

So, without the adb cheat, I’m still not able to open the menu.

After opening the Menu, I don’t know how to click on a sub-menu on it
I’ve tried “@driver.find_element(:name, “History”).click()”
but he can’t find nothing…
I didn’t know it was so complicated to open a Android menu and click on it during a Chrome session…