首页 > 系统相关 >windows 桌面GUI自动化- 18.pywinauto 保存控件菜单树结构print_control_identifiers()

windows 桌面GUI自动化- 18.pywinauto 保存控件菜单树结构print_control_identifiers()

时间:2023-08-26 15:12:18浏览次数:40  
标签:control 控件 树结构 pywinauto identifiers getpreferredencoding print

前言

.pywinauto 可以使用 print_control_identifiers() 方法打印控件菜单树结构,这对我们查找控件非常方便。

print_control_identifiers()

查看相关源码

    def print_control_identifiers(self, depth=None, filename=None):
        """
        Prints the 'identifiers'

        Prints identifiers for the control and for its descendants to
        a depth of **depth** (the whole subtree if **None**).

        .. note:: The identifiers printed by this method have been made
               unique. So if you have 2 edit boxes, they won't both have "Edit"
               listed in their identifiers. In fact the first one can be
               referred to as "Edit", "Edit0", "Edit1" and the 2nd should be
               referred to as "Edit2".
        """
       
    print_ctrl_ids = print_control_identifiers
    dump_tree = print_control_identifiers

print_ctrl_ids 和 dump_tree 实现的功能与print_control_identifiers等价,都是调用的print_control_identifiers 方法。
用2个参数

  • depth 查找框架深度,默认全部查找
  • filename 保存本地文件名称

保存本地文件

把打印的内容保存到本地txt,这样查看更方便

from pywinauto import Application


app = Application('uia').start("notepad.exe")
win = app.window(title_re="无标题 - 记事本")
win.print_ctrl_ids(filename="x1.txt")

在windows上运行后文件写入的中文内容有乱码

重新设保存文件默认编码可以解决此问题

from pywinauto import Application
import locale


def getpreferredencoding(do_setlocale = True):
    return "utf-8"


# 设置保存文件编码 "utf-8"
locale.getpreferredencoding = getpreferredencoding
print(locale.getpreferredencoding())

app = Application('uia').start("notepad.exe")
win = app.window(title_re="无标题 - 记事本")
win.print_ctrl_ids(filename="x1.txt")

标签:control,控件,树结构,pywinauto,identifiers,getpreferredencoding,print
From: https://www.cnblogs.com/yoyoketang/p/17658811.html

相关文章

  • cocos2dx之创建CCControlSlider
    采用CCControlSlider创建,代码如下:CCControlSlider*slider=CCControlSlider::create("extensions/sliderTrack.png","extensions/sliderProgress.png","extensions/sliderThumb.png"); slider->setAnchorPoint(ccp(0.5,1.0f)); slider->......
  • swift - 之TabBarController的用法
    TabBarController的使用,下面记录两种写法,代码如下:TabBarItem系统自带图标样式(System)介绍:Custom:自定义方式,配合SelectedImage来自定义图标More:三个点的图标,表示更多意思Favorites:星形图标Featured:星形图标TopTated:星形图标Recents:时钟图标Contacts:一个圆形一个人头像的图标,代表联......
  • WPF中窗口控件的跨线程调用
    在多线程里面,UI是不能直接跨线程使用的。在WinForm中,我们要跨线程访问窗口控件,只需要设置属性CheckForIllegalCrossThreadCalls=false;即可。在WPF中要设置Dispatcher属性。msg为要输出的内容privatedelegatevoidoutputDelegate(stringmsg);privatev......
  • 【Angular】如何将自定义组件绑定为FormControl?
    参考资料:简单Demo:AngularFormcontrolenameCustomComponent关键实现说明:ControlValueAccessor:CustomFormComponentsinAngularAngular自定义表单控件(中文)关于muti:true的说明......
  • WPF PasswordBox控件的使用
    在做登陆框的时候使用到PasswordBox,PasswordBox并不能像TextBox一样通过Binding就可以实现MVVM,需要用到依赖属性。 LoginView文件的代码:<StackPanelGrid.Row="0"Orientation="Horizontal"Margin="5"><TextBlockText="Username:"Width=&qu......
  • 遍历Tree控件中的节点
    classSapGuiTree:classTreeType(enum.Enum):SIMPLE=0LIST=1COLUMN=2@classmethoddefshow(cls,tree,node,indention):print(indention,node,[tree.GetItemText(node,col......
  • 从SAP TableControl中读取数据
    classSapGuiTableControl:"""读取GuiTableControl对象的数据。"""@staticmethoddefget_data(session,_id,columns=None):"""获取指定列的数据,索引从0开始。:paramsession:SAP的GuiSession......
  • windows 桌面GUI自动化- 14.pywinauto 找到多个相同控件使用found_index
    前言pywinauto在查找到多个相同控件时操作会报错,可以使用found_index选择其中的一个查找到多个查找control_type="MenuBar"的所有控件frompywinautoimportApplicationapp=Application('uia').start("notepad.exe")win=app.window(title_re="无标题-记事本")#......
  • LinkButton控件,点击按钮带参数到后台
    LinkButton实现带参数到后台方法详解一:LinkButton控件常用的属性Text:用于设置控件显示的文本内容。ToolTip:鼠标悬停在控件上时显示的提示信息。CommandArgument:用于向服务器端的事件处理程序传递额外的参数。CommandName:用于标识LinkButton的命令名称,用于区分不同的......
  • windows 桌面GUI自动化- 12.pywinauto 组合框控件ComboBox操作
    前言pywinauto组合框控件ComboBox操作场景记事本-另存为-编码选择,下图这种就是组合框控件ComboBoxselect选择官网给的教程是通过select选择选项示例frompywinautoimportApplicationapp=Application('uia').start("notepad.exe")win=app.window(title_re="......