解决这个问题有两种方法:
- 第一种方法是使用"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))
…………
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))
…………
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))
…………
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/