Emna Ayadi
Emna Ayadi

Reputation: 2460

Keyboard in Android physical device isn’t always hidden while using Appium

When I want to hide the keyboard, (because if I don't hide it when I click into a button under keyboard a number from keyboard is pressed instead of the confirm button for example) some times it's hidden ok by the command driver.hidekeyboard(); and other times it's hidden automatically.

Other times it tells me

An unknown server-side error occurred while processing the command. (Original error: Soft keyboard not present, cannot hide keyboard)

Upvotes: 5

Views: 3030

Answers (4)

Chandrashekhar Swami
Chandrashekhar Swami

Reputation: 1780

Use adb command to check whether keyboard has popped up or not

adb shell dumpsys input_method | grep mInputShown 

Output : mShowRequested=true mShowExplicitlyRequested=false mShowForced=false mInputShown=true

if mInputShown=true then yes software keyboard has popped up. Then use driver.pressKeyCode(AndroidKeyCode.BACK);

PS: Please do not use driver.navigate().back() as its behavior may not be same on all devices.

Upvotes: 4

Naman
Naman

Reputation: 31888

Faced a similar problem trying to work on emulator and real time devices. One had the keyboard displayed and another didn't. So the driver.hideKeyboard(); used to fail for the latter. Just made sure that the keyboard would appear in both the cases and then hidden.

driver.getKeyboard();
driver.hideKeyboard();

This works fine for me. Hope it helps.

Upvotes: 4

karthick23
karthick23

Reputation: 1331

Try to find a Static Text/link element on the page and .click() there. That dismisses the keyboard .

Upvotes: 2

karthick23
karthick23

Reputation: 1331

@Emna After inputting both field if hidekeyboard doesnt works try. driver.navigate().back(); or wrap it as

public void clickDeviceBackButton(){
        driver.navigate().back();
    }

and call clickDeviceBackButton() in your testcase

Upvotes: 2

Related Questions