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

 

最新文章

  1. d3.js读书笔记-2
  2. 1028作业:Java语法基础
  3. Ubuntu下deb包的安装方法 (zz)
  4. 坑人的微信新版支付(V3.3.6)
  5. 【高德地图API】如何设置Icon的imageSize?
  6. final和static
  7. Oracle基础(五) 权限管理
  8. [Codeforces137C]History(排序,水题)
  9. 【DELPHI】线程相关
  10. HW3.22
  11. CentOS 设置mysql的远程访问
  12. 为什么32位操作系统最大支持4GB内存
  13. zabbix监控Mysql中的QPS/TPS
  14. ssh登录后很慢 卡住 树莓派
  15. kafka的advertised.host.name参数 外网访问配置
  16. jieba分词(1)
  17. NLP自然语言处理系列5-支持向量机(SVM)
  18. 在Android工程中加入AIDL文件时,gen目录生成的文件报错-问题解决
  19. Set Matrix Zeroes leetcode java
  20. (笔记)Mysql命令show databases:显示所有数据库

热门文章

  1. LaTeX —— 特殊符号与数学字体
  2. c语言学习笔记(3)——输入输出
  3. Android开发 ----------怎样真机调试?
  4. matlab进行离散点的曲线拟合
  5. [转]TensorFlow如何进行时序预测
  6. 常用cl编译命令参数解释
  7. node 后台管理插件forever
  8. [原译]WPF绘制圆角多边形
  9. WPF中DataGrid自定义实现最后一行下面跟一个汇总行,类似MT4
  10. CSS,让100%的宽度,自动减10,让100%的高度,自动减10,可以加减乘除