首页 > 移动平台 > 详细

Appium 解决中文输入问题

时间:2017-10-28 10:29:58      阅读:301      评论:0      收藏:0      [点我收藏+]

文章出处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");

 

Appium 解决中文输入问题

原文:http://www.cnblogs.com/111testing/p/7745839.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!