首先通过 spy++ 工具定位树控件的类。
然后通过 get_item('\本地计算机 策略\计算机配置\管理模板')
层级定位的方式即可定位到树节点。
# -*- coding: UTF8 -*-
from pywinauto import Application
import psutil
def get_pid(name):
'''
作用:根据进程名获取进程pid
返回:返回匹配第一个进程的pid
'''
pids = psutil.process_iter()
for pid in pids:
if(pid.name() == name):
return pid.pid
app = Application().connect(process = get_pid("mmc.exe"))
win = app.window(title_re = "本地组策略编辑器")
# 定位到树控件
win_tree = win.child_window(class_name = 'SysTreeView32')
# 定位树结构里的管理模板节点
win_tree.get_item('\本地计算机 策略\计算机配置\管理模板').click()
我操作就是点击一下管理模板这个树节点,效果图如下:
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有