shiva1791
shiva1791

Reputation: 540

How to dismiss the keyboard in appium using Java?

This code just aims to find the textbox and send some text to it. When it does that the keyboard appears on the android device.How to dismiss it after the sendKeys.

@Test
    public static void test_demo() throws Exception {
        WebElement element = driver.findElement(By.id("mytextfield"));
        element.sendKeys("test");
        //how do I dismiss keyboard which appears on my android device after sendKeys?  
    }

Upvotes: 11

Views: 39359

Answers (10)

In Kotlin I created a function to check if keyboard is shown.

fun hideKeyboard() {
        val shownKeyboard = driver.executeScript("mobile: isKeyboardShown")
        if (shownKeyboard.equals(true)) {
            driver.executeScript("mobile: hideKeyboard")
        }
}

Upvotes: 0

Chaitanya Mankar
Chaitanya Mankar

Reputation: 11

driver.executeScript("mobile: hideKeyboard"); works for me.

Upvotes: 1

Dhinesh M
Dhinesh M

Reputation: 1

driver.hideKeyboard(); some times does not work. Because while running testcase keyboard not appear fast, So testcase fail. If I use Thread.sleep(5000); before hideKeyboard method, it's working very fine for me every time.

try {
    Thread.sleep(5000);
} catch (Exception e) {
    e.getMessage();
}
driver.hideKeyboard();

Upvotes: 0

Prasetyo Budi
Prasetyo Budi

Reputation: 96

public static AndroidDriver driver= null;
......

driver.hideKeyboard();

will work perfectly based on my experience.

Upvotes: 1

Al Imran
Al Imran

Reputation: 882

Solution for those who are not using AppiumDriver:

((AppiumDriver)driver).hideKeyboard(); 

Upvotes: 1

SOAlgorithm
SOAlgorithm

Reputation: 425

Add these desired capabilities values if you want to disable the keyboard on your android selenium tests.

capabilities.setCapability("unicodeKeyboard", true);
capabilities.setCapability("resetKeyboard", true);

Upvotes: 8

Santosh Pillai
Santosh Pillai

Reputation: 8653

I use driver.hideKeyboard(); every time I'm using sendKeys() to type something. Works perfectly for me.

Upvotes: 2

Eyal Sooliman
Eyal Sooliman

Reputation: 2248

driver.hideKeyboard() will only work with AppiumDriver. I am using java-client-2.2.0.jar that contains this capability.

Upvotes: 19

Abhishek Swain
Abhishek Swain

Reputation: 1054

Please use Appium 1.0

Add libraries or add maven dependency of Appium Java client:

<dependency>
  <groupId>io.appium</groupId>
  <artifactId>java-client</artifactId>
  <version>1.1.0</version>
</dependency>

Create driver instance in the following way:

AppiumDriver driver=null;
driver= new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"),capabilities);

And use the following function to hide the keyboard:

driver.hideKeyboard();

Upvotes: 2

user2220762
user2220762

Reputation: 565

Best way is to use the back button.

driver.navigate().back(); // For older version of appium

Upvotes: 8

Related Questions