很多朋友在使用pywinauto的時(shí)候會(huì)遇到其無法對(duì)中文應(yīng)用的菜單等操作的問題,其實(shí)這只是由于編碼引起的問題。
解決這個(gè)問題有兩種方法:
第一種方法是使用"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))
…………