Giter Site home page Giter Site logo

Control子类方法SendKeys()参数里面的interval和waitTime 怎么设置都很慢,大概停顿1-2秒。如何操作才能让他填写间隔很短。 about python-uiautomation-for-windows HOT 5 CLOSED

yinkaisheng avatar yinkaisheng commented on July 2, 2024
Control子类方法SendKeys()参数里面的interval和waitTime 怎么设置都很慢,大概停顿1-2秒。如何操作才能让他填写间隔很短。

from python-uiautomation-for-windows.

Comments (5)

yinkaisheng avatar yinkaisheng commented on July 2, 2024

我用微软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.

zhaowenjun333 avatar zhaowenjun333 commented on July 2, 2024
  • 老哥你说的那种操作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.

yinkaisheng avatar yinkaisheng commented on July 2, 2024

你的代码慢是因为时间都花在了查找控件上了,打字部分只占用很少时间,查找逻辑有点问题。
首先 先找到你的客户端的顶层窗口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.

zhaowenjun333 avatar zhaowenjun333 commented on July 2, 2024

老哥说的很详细非常感谢,这个是报税涉及的单元格太多了改起来真带劲,之前的航信开票的客户端也是用你的库效果非常棒。我已经用你库做了13个rpa流程了。 再次感谢。

from python-uiautomation-for-windows.

yinkaisheng avatar yinkaisheng commented on July 2, 2024

加了打印控件查找时长的功能,可以看看demos\automation_calculator.py

from python-uiautomation-for-windows.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.