如何使用 Java 在 appium 中关闭键盘?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23220067/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 21:25:10  来源:igfitidea点击:

How to dismiss the keyboard in appium using Java?

javaandroidappium

提问by shiva1791

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.

这段代码只是为了找到文本框并向它发送一些文本。当它这样做时,键盘出现在 android 设备上。如何在 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?  
    }

采纳答案by Eyal Sooliman

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

driver.hideKeyboard()只会与AppiumDriver. 我正在使用包含此功能的 java-client-2.2.0.jar。

回答by user2220762

Best way is to use the back button.

最好的方法是使用后退按钮。

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

回答by Abhishek Swain

Please use Appium 1.0

请使用 Appium 1.0

Add libraries or add maven dependency of Appium Java client:

添加库或添加 Appium Java 客户端的 maven 依赖:

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

回答by Santosh Pillai

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

我用driver.hideKeyboard();我使用的每一次sendKeys()输入的东西。非常适合我。

回答by Prasetyo Budi

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

driver.hideKeyboard();

will works perfectly based from my experience

将根据我的经验完美地工作

回答by SOAlgorithm

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

如果您想在 android selenium 测试中禁用键盘,请添加这些所需的功能值。

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

回答by Bahaderjon Ahunov

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

Still works with 1.7.2 and assuming 1.8

仍然适用于 1.7.2 并假设为 1.8

回答by Al Imran

Solution for those who are not using AppiumDriver:

对于那些不使用的人的解决方案AppiumDriver

((AppiumDriver)driver).hideKeyboard();