Comments (5)
我用微软excel试了并没有出现变慢的情况。
你手动打字看看是不是慢的?或者在系统记事本上用代码打字看看是不是慢的?
快速修改可以先把要输入的内容设置到剪贴板,然后点击表格,按ctrl v粘贴,比打字快点。
uiautomation.SetClipboardText('text to type')
control.Click(simulateMove=False, waitTime=0)
control.SendKeys('{Ctrl}v', waitTime=0)
如果是excel文件的话可以使用其它module(openpyxl or xlrd)直接读取修改文件。
from python-uiautomation-for-windows.
- 老哥你说的那种操作excel我就是用的你说的openpyxl,抱歉,我可能没描述清楚现在具体情况是这样的。
- 我这边是window报税客户端,先数据预处理从19个excel模板中用pandas提取出固定的数据格式datadict,然后把对应excel中的数据填写到客户端中,取代人去填写。从而节约了大量的时间和人力成本

python automation.py -r -f -c -a -n -m
- 我的思路是先用这个定位到客户端某个句柄位置,然后从提取好的数据datadict中拿到第一个表的数据data1去填写报税客户端第一个页面。
for i in range(8):#第一行八个单元格数据
if EditControl(AutomationId ='cellR001C00'+str(i+1),searchDepth=13).Exists(4):
EditControl(AutomationId='cellR001C00'+str(i+1), searchDepth=13).SendKeys('0' if data1[i] == '' else data1[i] ,waitTime = 0.01)
- 可以正常填写但是速度比较慢。我的意思waitTime 从0.5 修改为0.01后 如果可以再快点就更好了。
from python-uiautomation-for-windows.
你的代码慢是因为时间都花在了查找控件上了,打字部分只占用很少时间,查找逻辑有点问题。
首先 先找到你的客户端的顶层窗口window,并保存为一个变量,然后从这个window再开始查找你要操作的控件。把你要操作的控件保存到变量里,后面用这个变量接着操作控件。
上面你的代码没有把EditControl保存到一个变量里,第二次调用SendKeys的时候你又创建了一个新的EditControl对象。
“if EditControl(AutomationId ='cellR001C00'+str(i+1),searchDepth=13).Exists(4)”这一行代码是没有用的,
4秒内这个控件查找到了,这个控件对象内部有个状态标志标识控件查找到了。
但调用SendKeys的对象是另一个新的临时对象,不是之前的对象,这个对象内部没有查找成功的标志。还会再重新查找一次,总共会花两次查找时间。
应该这样写:
import uiautomation as auto
window = auto.WindowControl(searchDepth = 1, Name='your window name')
for i in range(8):#第一行八个单元格数据
edit = window.EditControl(AutomationId ='cellR001C00'+str(i+1),searchDepth=12)
if edit.Exists(4):
edit.SendKeys('0' if data1[i] == '' else data1[i] ,waitTime = 0.01)
如果还慢的话,需要再分层查找控件。
假如控件树结构是这样的
root
window1
control1-001
...
control1-100
window2(Name='window2')
control2-1
control2-1-001
....
control2-1-100
control2-2
control2-3
control2-4(Name='2-4')
editcontrol(Name='myedit1')
editcontrol(Name='myedit2')
你想找到window2下面的第二个editcontrol,如果你这样写
EditControl(searchDepth=3, Name='myedit2').SendKeys(’hi‘)
将会查找200多次才能找到控件,因为要先遍历前三层中排在EditControl之前的控件,有200多个。
如果这样写
window2 = auto.WindowControl(searchDepth=1,Name='window2')#查找2次
sub = window2.Control(searchDepth=1, Name='2-4')#查找4次
edit = sub.EditControl(searchDepth=1, Name='myedit2')#查找2次
edit.SendKeys('hi')
只需要查找几次就能快速找到EditControl,代码虽然多点但花时间少。
你需要把你的软件整个控件树打印出来,看中间某层是不是控件太多,想办法分层查找减少查找次数。
from python-uiautomation-for-windows.
老哥说的很详细非常感谢,这个是报税涉及的单元格太多了改起来真带劲,之前的航信开票的客户端也是用你的库效果非常棒。我已经用你库做了13个rpa流程了。 再次感谢。
from python-uiautomation-for-windows.
加了打印控件查找时长的功能,可以看看demos\automation_calculator.py
from python-uiautomation-for-windows.
Related Issues (20)
- Win 11 x64 系统无法获取元素 HOT 3
- SendKeys密码框会丢失掉部分字符 HOT 2
- About release notes HOT 1
- Find ALL 和 find First 还不能使用吗?
- 无法捕获右键菜单点击内容值 HOT 1
- 如何选中DataGridControl里面的子选项
- Publish uiautomation as a conda package : requires pypi Source Distribution HOT 2
- 企业微信无法获取信息 HOT 2
- Add source distribution to pypi - to create conda-forge package HOT 1
- 方法 .WindowControl 和 .Control 有什么区别? HOT 1
- IsOffscreen 为什么会报错 HOT 1
- EditControl控件如何获得联想词列表?
- 请问应该怎么实现对元素进行鼠标悬停呢 HOT 1
- 希望可以对UIAumation的事件进行支持 HOT 1
- Add py.typed to the distribution
- powershell环境运行 automation.py -h 自动闪退 HOT 1
- 同时使用Python-UIAutomation-for-Windows和pyside6报错的问题 HOT 1
- SetGlobalSearchTimeout貌似没有起作用 HOT 2
- 打印pyqt5软件的控件信息时会无限循环
- 如何让点击控件鼠标移动速度快一点呢?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-uiautomation-for-windows.