Appium+python 使用 press_keycode 如何输入大写字母

2019/04/17 10:12
阅读数 208

背景:在做自动化测试项目时,需要在文本框中输入一串数字和字母组合的字符串(注:此页面为webview无法使用send_keys方法)

要使用send_keys方法首先要知道键盘字符对应的数值,这个可以在网上百度下,我把相关的对应关系已逻列到了下边,从以下对应

关系可知大写字母A和小字字母a对应的数值都是29, 在使用press_keycode(29) 时,文本框中输出的是小写的a,那如何输入大写的A呢?

分析: 查看press_keycode函数说明: def press_keycode(self, keycode, metastate=None, flags=None)

:Args:

- keycode - the keycode to be sent to the device   发送到设备的键值编码
- metastate - meta information about the keycode being sent   将被发送的元信息
- flags - the set of key event flags  设置的按键事件标记

我们通过键盘正常输入大写字母的操作方式 有三种 1,按下左侧shift键+字母   2. 按下右侧shift键+字母  3.按下caps_lock大小写锁定键输入字符

方法:我们以采用每一个方法为例输入大写字母A 

依次输入参数1输入字母A对应的数值 29  ,参数2 将元信息左shift 开关打开,参数3 模拟输入按下左shift键

(注:'META_SHIFT_LEFT_ON':64 'KEYCODE_SHIFT_LEFT':59  )

press_keycode(29,64,59)

 心得:由此方法可知,press_keycode 是可以模拟键盘的组如输入的如shifte+键盘,ctrl+键盘等等,需要与 META_键_ON 同时运用。     

 

def getMobileKey():
key={'0':7,'1':8,'2':9,'3':10,'4':11,'5':12,'6':13,'7':14,'8':15,'9':16,
'A':29,'B':30,'C':31,'D':32,'E':33,'F':34,'G':35,'H':36,'I':37,'J':38,
'K':39,'L':40,'M':41,'N':42,'O':43,'P':44,'Q':45,'R':46,'S':47,'T':48,
'U':49,'V':50,'W':51,'X':52,'Y':53,'Z':54,
'a':29,'b':30,'c':31,'d':32,'e':33,'f':34,'g':35,'h':36,'i':37,'j':38,
'k':39,'l':40,'m':41,'n':42,'o':43,'p':44,'q':45,'r':46,'s':47,'t':48,
'u':49,'v':50,'w':51,'x':52,'y':53,'z':54,
'META_ALT_LEFT_ON':16,
'META_ALT_MASK':50,
'META_ALT_ON':2,
'META_ALT_RIGHT_ON':32,
'META_CAPS_LOCK_ON':1048576,
'META_CTRL_LEFT_ON': 8192,
'META_CTRL_MASK':28672,
'META_CTRL_ON':4096,
'META_CTRL_RIGHT_ON':16384,
'META_FUNCTION_ON':8,
'META_META_LEFT_ON':131072,
'META_META_MASK':458752,
'META_META_ON':65536,
'META_META_RIGHT_ON':262144,
'META_NUM_LOCK_ON':2097152,
'META_SCROLL_LOCK_ON':4194304,
'META_SHIFT_LEFT_ON':64,
'META_SHIFT_MASK':193,
'META_SHIFT_ON':1,
'META_SHIFT_RIGHT_ON':128,
'META_SYM_ON':4,
'KEYCODE_APOSTROPHE':75,
'KEYCODE_AT':77,
'KEYCODE_BACKSLASH':73,
'KEYCODE_COMMA':55,
'KEYCODE_EQUALS':70,
'KEYCODE_GRAVE':68,
'KEYCODE_LEFT_BRACKET':71,
'KEYCODE_MINUS':69,
'KEYCODE_PERIOD':56,
'KEYCODE_PLUS':81,
'KEYCODE_POUND':18,
'KEYCODE_RIGHT_BRACKET':72,
'KEYCODE_SEMICOLON':74,
'KEYCODE_SLASH':76,
'KEYCODE_STAR':17,
'KEYCODE_SPACE':62,
'KEYCODE_TAB':61,
'KEYCODE_ENTER':66,
'KEYCODE_ESCAPE':111,
'KEYCODE_CAPS_LOCK':115,
'KEYCODE_CLEAR':28,
'KEYCODE_PAGE_DOWN':93,
'KEYCODE_PAGE_UP':92,
'KEYCODE_SCROLL_LOCK':116,
'KEYCODE_MOVE_END':123,
'KEYCODE_MOVE_HOME':122,
'KEYCODE_INSERT':124,
'KEYCODE_SHIFT_LEFT':59,
'KEYCODE_SHIFT_RIGHT':60,
'KEYCODE_F1':131,
'KEYCODE_F2':132,
'KEYCODE_F3':133,
'KEYCODE_F4':134,
'KEYCODE_F5':135,
'KEYCODE_F6':136,
'KEYCODE_F7':137,
'KEYCODE_F8':138,
'KEYCODE_F9':139,
'KEYCODE_F10':140,
'KEYCODE_F11':141,
'KEYCODE_F12':142,
'KEYCODE_BACK':4,
'KEYCODE_CALL':5,
'KEYCODE_ENDCALL':6,
'KEYCODE_CAMERA':27,
'KEYCODE_FOCUS':80,
'KEYCODE_VOLUME_UP':24,
'KEYCODE_VOLUME_DOWN':25,
'KEYCODE_VOLUME_MUTE':164,
'KEYCODE_MENU':82,
'KEYCODE_HOME':3,
'KEYCODE_POWER':26,
'KEYCODE_SEARCH':84,
'KEYCODE_NOTIFICATION':83,
'KEYCODE_NUM':78,
'KEYCODE_SYM':63,
'KEYCODE_SETTINGS':176,
'KEYCODE_DEL':67,
'KEYCODE_FORWARD_DEL':112,
'KEYCODE_NUMPAD_0':144,
'KEYCODE_NUMPAD_1':145,
'KEYCODE_NUMPAD_2':146,
'KEYCODE_NUMPAD_3':147,
'KEYCODE_NUMPAD_4':148,
'KEYCODE_NUMPAD_5':149,
'KEYCODE_NUMPAD_6':150,
'KEYCODE_NUMPAD_7':151,
'KEYCODE_NUMPAD_8':152,
'KEYCODE_NUMPAD_9':153,
'KEYCODE_NUMPAD_ADD':157,
'KEYCODE_NUMPAD_COMMA':159,
'KEYCODE_NUMPAD_DIVIDE':154,
'KEYCODE_NUMPAD_DOT':158,
'KEYCODE_NUMPAD_EQUALS':161,
'KEYCODE_NUMPAD_LEFT_PAREN':162,
'KEYCODE_NUMPAD_MULTIPLY':155,
'KEYCODE_NUMPAD_RIGHT_PAREN':163,
'KEYCODE_NUMPAD_SUBTRACT':156,
'KEYCODE_NUMPAD_ENTER':160,
'KEYCODE_NUM_LOCK':143,
'KEYCODE_MEDIA_FAST_FORWARD':90,
'KEYCODE_MEDIA_NEXT':87,
'KEYCODE_MEDIA_PAUSE':127,
'KEYCODE_MEDIA_PLAY':126,
'KEYCODE_MEDIA_PLAY_PAUSE':85,
'KEYCODE_MEDIA_PREVIOUS':88,
'KEYCODE_MEDIA_RECORD':130,
'KEYCODE_MEDIA_REWIND':89,
'KEYCODE_MEDIA_STOP':86,
}
return key

展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部