Hi everyone,
I’m writing mobile automation tests using Katalon Studio, running on a real Android device.
In my test case, I tap on an input field (EditText), and at that point, the soft keyboard is expected to appear so the user can type.
I want to verify whether the keyboard is actually shown or not, but:
- I couldn’t find any built-in Katalon keyword like
Mobile.isKeyboardShown()
.
- When inspecting the UI hierarchy using Spy Mobile (or at runtime), I don’t see any XPath or UI node that represents the keyboard, even when it’s clearly visible on the screen.
Is there any way to check if the keyboard is currently displayed using Katalon or Appium directly?
1 Like
Hi there, and thanks for posting in the Katalon community! 
To help you faster, please review our guide on Record Mobile Utility here:
Double-checking the steps and configurations might resolve the issue.
If the doc doesn’t help, feel free to provide more details, and a community member will assist you soon.
Thanks for being a part of our community!
Best,
Elly Tran
1. Using Appium’s isKeyboardShown
Method (Recommended)
groovy
import io.appium.java_client.AppiumDriver
import com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactory
// After tapping the input field
AppiumDriver<?> driver = MobileDriverFactory.getDriver()
boolean isKeyboardVisible = driver.isKeyboardShown()
// Assert visibility
if (isKeyboardVisible) {
println("Keyboard is displayed")
} else {
throw new Exception("Keyboard not shown after tapping input field")
}
2. Check for Keyboard UI Elements (Fallback)
If the keyboard exists in the UI hierarchy, use object recognition:
groovy
TestObject keyboardKey = findTestObject('Object Repository/android.widget.Button - Enter_key')
try {
Mobile.verifyElementVisible(keyboardKey, 5)
println("Keyboard detected via UI element")
} catch (Exception e) {
println("Keyboard not found in UI hierarchy")
}
Use Katalon’s Mobile Spy while keyboard is visible to identify unique elements (e.g., “Enter” key).
3. Screen Height Comparison
groovy
import org.openqa.selenium.Dimension
// Get screen dimensions
Dimension initialSize = MobileDriverFactory.getDriver().manage().window().size
int initialHeight = initialSize.height
// Tap input field
Mobile.tap(testObject, 0)
// Get new dimensions
Dimension newSize = MobileDriverFactory.getDriver().manage().window().size
int newHeight = newSize.height
// Keyboard reduces visible screen height
boolean isKeyboardVisible = (newHeight < initialHeight)
4. ADB Command Approach (For Rooted/Dev Devices)
groovy
import com.kms.katalon.core.util.KeywordUtil
String adbCommand = 'adb shell dumpsys input_method | grep mInputShown'
Process process = Runtime.getRuntime().exec(adbCommand)
process.waitFor()
BufferedReader reader = new BufferedReader(new InputStreamReader(process.inputStream))
String output = reader.readLine()
// Parse ADB output
if (output?.contains("mInputShown=true")) {
KeywordUtil.logInfo("Keyboard active (ADB confirmed)")
} else {
KeywordUtil.markFailed("Keyboard not detected via ADB")
}
Implementation Notes:
- Keyboard Element Identification:
- Use Katalon Mobile Spy with keyboard visible
- Common keyboard objects:
groovy
TestObject enterKey = findTestObject('Object Repository/android.widget.Button - Enter')
TestObject spaceKey = findTestObject('Object Repository/android.widget.Button - Space')
- Best Practices:
groovy
// Wait for keyboard to animate
Mobile.delay(2)
// Combine methods for reliability
boolean confirmed = driver.isKeyboardShown() || Mobile.waitForElementPresent(keyboardKey, 3)
- Common Pitfalls:
- Keyboard might not appear if:
- Device is in physical keyboard mode
- Using non-standard keyboards (Gboard, SwiftKey)
- Element isn’t focusable (check
clickable=true
in properties)
Sample Workflow:
groovy
Mobile.startApplication('app.apk', false)
Mobile.tap(findTestObject('Login/input_Username'), 0)
// Method 1: Appium direct check
if (!((AppiumDriver) MobileDriverFactory.getDriver()).isKeyboardShown()) {
Mobile.takeScreenshot('keyboard_missing.png')
KeywordUtil.markFailed("Keyboard not displayed")
}
// Method 2: Hybrid verification
TestObject spaceKey = findTestObject('Keyboard/Space')
try {
Mobile.waitForElementPresent(spaceKey, 5)
} catch (Exception e) {
Mobile.pressBack() // Attempt to close keyboard if stuck
throw e
}
2 Likes