Appium 解决中文输入问题

文章出处http://blog.csdn.net/meyoung01/article/details/43286265

Appium不支持中文,废了好大的劲都没搞定。 最后用了个土办法勉强解决,直接见下封装好的代码:

[java] view plain copy
/** 
 * 输入中文,并返回 
 * 
 * @param driver driver 
 * @param text   例如想输入”中国“则传值为"zhongguo" 
 * @param by     定位你想获取文本的控件 
 * @return 
 */  
public static String sendText(AndroidDriver driver, String text, By by) {  
    String returnText = null;  
    try {  
        Thread.sleep(2000);  
        Process pro = Runtime.getRuntime().exec("cmd /c adb shell input text " +  text);  
Thread.sleep(
1500); Runtime.getRuntime().exec("cmd /c adb shell input keyevent KEYCODE_SPACE"); Thread.sleep(2000); returnText = driver.findElement(by).getText(); } catch (IOException e) { } catch (InterruptedException e) { e.printStackTrace(); } return returnText; } 注意调用这个方法时,键盘必须设置成默认系统键盘,并可以中文输入的键盘。 偶然发现其实已经支持了中文等字符的输入, 只要在capabilities中增加下列两项设置就可以: capabilities.setCapability("unicodeKeyboard", "True"); capabilities.setCapability("resetKeyboard", "True");


注意调用这个方法时,键盘必须设置成默认系统键盘,并可以中文输入的键盘。

偶然发现其实已经支持了中文等字符的输入,

只要在capabilities中增加下列两项设置就可以:

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

原文地址:https://www.cnblogs.com/111testing/p/7745839.html