您的位置:軟件測(cè)試 > 開(kāi)源軟件測(cè)試 > 開(kāi)源功能測(cè)試工具 >
讓Pywinauto支持中文菜單
作者:網(wǎng)絡(luò)轉(zhuǎn)載 發(fā)布時(shí)間:[ 2012/12/21 15:49:09 ] 推薦標(biāo)簽:

   很多朋友在使用pywinauto的時(shí)候會(huì)遇到其無(wú)法對(duì)中文應(yīng)用的菜單等操作的問(wèn)題,其實(shí)這只是由于編碼引起的問(wèn)題。

    解決這個(gè)問(wèn)題有兩種方法:

    第一種方法是使用"u"講字符串轉(zhuǎn)換成UTF格式的字符串:

  
…………
EDIT_NAME = u'保存網(wǎng)頁(yè)'
SAVE_NAME = u'保存(&S)'
ASK_NAME = u'保存網(wǎng)頁(yè)'
YES_NAME = u'是(&Y)'

…………

app = Application().start_(r"c:program filesinte.net exploreriexplore.exe %s"% web_addresss)

time.sleep(1)

ie = app.window_(title_re = ".*Microsoft Internet Explorer.*")

print "No Menu's in IE:", ie.MenuItems()
print "They are implemented as a toolbar:", ie.Toolbar3.Texts()

ie.TypeKeys("%FA")
SaveWebPage = app[EDIT_NAME]
SaveWebPage['Edit'].SetEditText(os.path.join(r"c:.temp",outputfilename))

…………

    第二種則是使用decode函數(shù)強(qiáng)行轉(zhuǎn)換字符串的編碼:

…………

CP = 'cp936'
EDIT_NAME = '保存網(wǎng)頁(yè)'.decode(CP)
SAVE_NAME = '保存(&S)'.decode(CP)
ASK_NAME = '保存網(wǎng)頁(yè)'.decode(CP)
YES_NAME = '是(&Y)'.decode(CP)

…………

app = Application().start_(r"c:program filesinternet exploreriexplore.exe %s"% web_addresss)

time.sleep(1)

ie = app.window_(title_re = ".*Microsoft Internet Explorer.*")

print "No Menu's in IE:", ie.MenuItems()
print "They are implemented as a toolbar:", ie.Toolbar3.Texts()

ie.TypeKeys("%FA")
SaveWebPage = app[EDIT_NAME]
SaveWebPage['Edit'].SetEditText(os.path.join(r"c:.temp",outputfilename))

…………

軟件測(cè)試工具 | 聯(lián)系我們 | 投訴建議 | 誠(chéng)聘英才 | 申請(qǐng)使用列表 | 網(wǎng)站地圖
滬ICP備07036474 2003-2017 版權(quán)所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd