zoukankan      html  css  js  c++  java
  • 让Pywinauto支持中文菜单

        很多朋友在使用pywinauto的时候会遇到其无法对中文应用的菜单等操作的问题,其实这只是由于编码引起的问题。

        解决这个问题有两种方法:

    • 第一种方法是使用"u"讲字符串转换成UTF格式的字符串:
       
    …………
    EDIT_NAME 
    = u'保存网页'
    SAVE_NAME 
    = u'保存(&S)'
    ASK_NAME 
    = u'保存网页'
    YES_NAME 
    = u'是(&Y)'

    …………

    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))

    …………

    • 第二种则是使用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))

    …………


  • 相关阅读:
    this用法
    break/continue的使用
    解决:sql server无法在C盘下创建database/操作系统错误5(拒绝访问)
    (转)科普:SATA、PCIe、AHCI、NVMe
    Java按位取反运算符“~”的工作原理
    <剑指offer> 第12题
    <剑指offer> 第11题
    <剑指offer> 第10题
    <剑指offer> 第9题
    <剑指offer> 第8题
  • 原文地址:https://www.cnblogs.com/guanhe/p/794762.html
Copyright © 2011-2022 走看看