讓Pywinauto支持中文菜單

發表于:2008-05-26來源:作者:點擊數: 標簽:Pywinauto菜單中文
很多朋友在使用pywinauto的時候會遇到其無法對中文應用的菜單等操作的問題,其實這只是由于編碼引起的問題。 解決這個問題有兩種方法: 第一種方法是使用"u"講字符串轉換成UTF格式的字符串: ………… EDIT_NAME = u ' 保存網頁 ' SAVE_NAME = u ' 保存(S) '
   很多朋友在使用pywinauto的時候會遇到其無法對中文應用的菜單等操作的問題,其實這只是由于編碼引起的問題。

    解決這個問題有兩種方法:

  • 第一種方法是使用"u"講字符串轉換成UTF格式的字符串:
   
…………
EDIT_NAME 
= u'保存網頁'
SAVE_NAME 
= u'保存(&S)'
ASK_NAME 
= u'保存網頁'
YES_NAME 
= u'是(&Y)'

…………

app = Application().start_(r"c:\program files\inte.net explorer\iexplore.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函數強行轉換字符串的編碼:
…………

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

…………

app 
= Application().start_(r"c:\program files\internet explorer\iexplore.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))

…………

原文轉自:http://www.anti-gravitydesign.com

国产97人人超碰caoprom_尤物国产在线一区手机播放_精品国产一区二区三_色天使久久综合给合久久97