How to dismiss the keyboard in appium using Java?

2019-04-05 13:21发布

问题:

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?  
    }

回答1:

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



回答2:

Best way is to use the back button.

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


回答3:

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);


回答4:

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();


回答5:

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



回答6:

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

driver.hideKeyboard();

will works perfectly based from my experience



回答7:

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

Still works with 1.7.2 and assuming 1.8