Pywinauto - 需要10秒钟才能执行操作

时间:2018-03-06 18:36:36

标签: pywinauto

我正在使用pywinauto尝试自动化Windows应用程序,我注意到每个操作大约需要10秒才能执行。它有效,但速度很慢,鉴于这是我第一次使用pywinauto,我可能做错了。

任何帮助将不胜感激 版本 0.6.4

self.main_wnd_spec.wait(wait_for='ready', timeout=50)
create = self.main_wnd_spec.child_window(title='Create', control_type="Window")

import time
start_time = time.time()
    type_= ComboBoxWrapper(create.child_window(
        title="Type:", auto_id="27651", control_type="ComboBox")
    )
    type_.select(1)
    print("--- %s seconds ---" % (time.time() - start_time))

start_time = time.time()
    severity= EditWrapper(create.child_window(title="Severity:", auto_id="27653", control_type="Edit"))
    severity.SetEditText('1')
    print("--- %s seconds ---" % (time.time() - start_time))

输出

--- 10.8264000415802 seconds ---
--- 10.514400005340576 seconds ---

控制标识符

 Dialog - 'Create'    (L604, T269, R1317, B772)
 ['Dialog', 'Create', 'Create Dialog']
 child_window(title="Create", control_type="Window")
  | 
  | ComboBox - 'Type:'    (L740, T334, R1165, B355)
  | ['Type:2', 'ComboBox', 'Batch class:ComboBox', 'ComboBox0', 'ComboBox1']
  | child_window(title="Type:", auto_id="27651", control_type="ComboBox")
  |    | 
  |    | Static - 'Type:'    (L3, T3, R405, B18)
  |    | ['Type:3', 'Static2', 'Batch class:Static2']
  |    | child_window(title="Type:", control_type="Text")
  |    | 
  |    | Button - 'Open'    (L1149, T335, R1164, B354)
  |    | ['Button', 'Open', 'OpenButton', 'Button0', 'Button1', 'Open0', 
         'Open1', 'OpenButton0', 'OpenButton1']
  |    | child_window(title="Open", auto_id="DropDown", control_type="Button")
  | 
  | Edit - 'Severity:'    (L1247, T334, R1278, B354)
  | ['Edit', '', 'Severity:Edit', 'Edit0', 'Edit1', '0', '1']
  | child_window(title="Severity:", auto_id="27653", control_type="Edit")

1 个答案:

答案 0 :(得分:1)

我已经弄清楚为什么搜索时间超过10秒。我正在回答我自己的问题,对于那些不想通过评论的人来说。

根据Vasily Ryabov的评论,当你创建一个包装器对象时,搜索从root开始,在我的例子中,root有超过8500个后代,当我设法减少通过app的后代数量时,搜索时间下降到

--- 1.2239999771118164 seconds ---
--- 0.9530003070831299 seconds ---