How to know if android virtual keyboard is open

Hello guys,
I’m working in Ruby.
My question is simple, how do you if the android virtual keyboard is open when we are on an app ?
Because sometimes in my app the virtual keyboard is automatically open and I have to press back. And sometimes no…
So I’m looking for a simple “if condition” to know if I have to press back or not in my auto test.
Thanks !

Use the hide_keyboard method.

Thanks for the answer but I have a big problem. It’s pretty much my main and only problem: I don’t know how to use the appium_lib function, they are not recognized when I compil.
I don’t know how to declare my driver so I can use them. I have the gem installed but my code is only working when 'm using Selenium and Watir.
Something like Appium::Browser or else are not working.
Can you give me just one exemple of project’s begin with declaration using appium_lib ? It’s like weeks I’m stuck.
Thanks a lot.
My code:

require ‘rubygems’
require ‘watir-webdriver’
require ‘rspec’
require ‘page-object’
require ‘page-object/page_factory’
require ‘require_relative’
require ‘yaml’
require ‘selenium-webdriver’
require ‘appium_lib’
capabilities =
‘appPackage’=> ‘com.myapp.demo’,
‘appActivity’=> ‘.MainActivity’,
‘platformName’ => ‘Android’,
‘deviceName’ => ‘Galaxy S4’,
server_url = ‘
@driver = Selenium::WebDriver.for(:remote, desired_capabilities: capabilities, url: server_url)
@browser = @driver
@browser.driver.manage.timeouts.implicit_wait = 30
@driver.find_element(:id, “com.myapp.demo:id/fbutton2”).click()

—> I can’t use appium_lib function with that.

Selenium::WebDriver is the problem. You need to create an appium driver. See the Ruby examples.

Thanks a lot, it’s ok !!
I finally get it, now I put @driver = and I can use Appium_lib functions.
hide_keyboard is working great but do you know how to know if the keyboard is open or not ? Because if I run hide_keyboard when it’s not open, I have an error.
Thanks again !

I find a way: I just catch the exception like this

begin @driver.hide_keyboard
rescue => e

and no problem.
Thanks again for your help!

I’m also working in Ruby.I have met with some problem in accessing the Appium methods.Can you share your env.rb file??
Thanks in advance

Here you can find a simple example of a entire script which using appium_lib gem

require ‘rubygems’
require ‘rspec’
require ‘watir-webdriver’
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 =
@driver = @driver_appium.start_driver
@browser = @driver
@browser.driver.manage.timeouts.implicit_wait = 15

With that, you can use @driver or @driver_appium to use Appium methods (I don’t know exactly what to use and when because I’m new too but I know this start code is a good start).

I have an example env.rb in the sample code repo for Ruby.

@Ericzered @bootstraponline

hide_keyboard is not waiting for android keyboard any more with latest appium server ?

can you please clarify is something changed wrt this method ?