原创-使用pywinauto进行dotnet的winform程序控制(一)
2024-08-28 03:23:37
pywinauto自动化控制win32的ui的程序,网上有好多的教程。但是操作dotnet写的winform教程,就少之又少。今天我就来分享我的pywinauto操作dotnet的winform的研究。
我自己写了个dotnet4的winform程序,样子是这样的
在第一个输入框输入文字后,点击“设置”,就能在下面的输入框同时显示
然后,我就打开WinSpy++.exe分析这个dotnet4写的winform,发现层次是这样的:
下图是与以vc写的win32的gui程序的winspy的分析
而参照该博主的博客文章https://blog.csdn.net/qq_37193537/article/details/81206788
winspy++的分析
进行画葫芦的分析dotnet写的winform,代码如下:
from pywinauto.application import Application
app= Application().start("WindowsFormsInput.exe")#.exe的路径是正确的,修改自己的路径
form = app.window_(title_re=u"Form1", class_name="WindowsForms10.Window.8.app.0.141b42a_r16_ad1")# form.print_control_identifiers()
以下是输出:
E:\py\autogui>python win32dotnet.py
win32dotnet.py:: DeprecationWarning: Method .window_() is deprecated, use .wind
ow() instead.
form = app.window_(title_re=u"Form1", class_name="WindowsForms10.Window.8.app.
.141b42a_r16_ad1")#
Control Identifiers: WindowsForms10.Window..app..141b42a_r16_ad1 - 'Form1' (L88, T88, R388, B388
)
['WindowsForms10.Window.8.app.0.141b42a_r16_ad1', 'Form1', 'Form1WindowsForms10.
Window..app..141b42a_r16_ad1']
child_window(title="Form1", auto_id="Form1", control_type="WindowsFormsInput.For
m1")
|
| Button - 'clear' (L251, T324, R326, B347)
| ['clearButton', 'Button', 'clear', 'Button0', 'Button1']
| child_window(title="clear", auto_id="button2", control_type="System.Windows
.Forms.Button")
|
| Button - '设置' (L162, T324, R237, B347)
| ['Button2', '设置Button', '设置']
| child_window(title="设置", auto_id="button1", control_type="System.Windows.
Forms.Button")
|
| Edit - 'E:\py\autogui\ce.png' (L162, T246, R326, B267)
| ['Form1Edit', 'Edit', 'Form1Edit0', 'Form1Edit1', 'Edit0', 'Edit1']
| child_window(title="E:\py\autogui\ce.png", auto_id="textBox3", control_type
="System.Windows.Forms.TextBox")
|
| Edit - '' (L162, T193, R326, B214)
| ['Form1Edit2', 'Edit2']
| child_window(auto_id="textBox2", control_type="System.Windows.Forms.TextBox
")
|
| Edit - '' (L162, T146, R326, B167)
| ['Form1Edit3', 'Edit3']
| child_window(auto_id="textBox1", control_type="System.Windows.Forms.TextBox
")
初步分析dotnet的win的控件排序与打印的是倒序了。
增加了在第一个Edit中输入字符串:
from pywinauto.application import Application
app= Application().start("WindowsFormsInput.exe")#.exe的路径是正确的,修改自己的路径
form = app.window_(title_re=u"Form1", class_name="WindowsForms10.Window.8.app.0.141b42a_r16_ad1") form.Form1Edit3.type_keys(r"E:\py\autogui\ce.png")
控制点击“设置”按钮
from pywinauto.application import Application
app= Application().start("WindowsFormsInput.exe")#.exe的路径是正确的,修改自己的路径
form = app.window_(title_re=u"Form1", class_name="WindowsForms10.Window.8.app.0.141b42a_r16_ad1")#
form.Form1Edit3.type_keys(r"E:\py\autogui\ce.png")
#form.Button2.click() #同样起作用
form.设置.click()
最新文章
- d3.js读书笔记-2
- 1028作业:Java语法基础
- Ubuntu下deb包的安装方法 (zz)
- 坑人的微信新版支付(V3.3.6)
- 【高德地图API】如何设置Icon的imageSize?
- final和static
- Oracle基础(五) 权限管理
- [Codeforces137C]History(排序,水题)
- 【DELPHI】线程相关
- HW3.22
- CentOS 设置mysql的远程访问
- 为什么32位操作系统最大支持4GB内存
- zabbix监控Mysql中的QPS/TPS
- ssh登录后很慢 卡住 树莓派
- kafka的advertised.host.name参数 外网访问配置
- jieba分词(1)
- NLP自然语言处理系列5-支持向量机(SVM)
- 在Android工程中加入AIDL文件时,gen目录生成的文件报错-问题解决
- Set Matrix Zeroes leetcode java
- (笔记)Mysql命令show databases:显示所有数据库