【问题标题】:Cannot get pywinauto to click button无法让 pywinauto 单击按钮
【发布时间】:2020-12-27 04:13:36
【问题描述】:

我正在尝试使用pywinauto 运行大量exe 文件,这些文件将项目添加到现有应用程序。 exe 文件按预期启动,并出现感兴趣的对话框(如下),但我无法单击对话框中的“下一步”按钮。看起来pywinauto 找不到“下一步”按钮。一个想法如何让他工作?这是我的代码:

import time
import pywinauto


def do_installs():
    app = pywinauto.application.Application()
    app.start("You're_a_Hoot_Brushes-(lrd)_windows.exe")

    # setup wizard starts
    # a "Setup" windows appears with a `Next >" button that I want to click

    time.sleep(10)  # excessive wait for Setup dialog

    dlg = app['Setup']
    print('dlg:')
    dlg.print_control_identifiers()
    dlg['Next'].click()


if __name__ == '__main__':
    do_installs()

这是输出日志:

C:\Users\John\AppData\Local\Programs\Python\Python38-32\python.exe C:/Users/John/PycharmProjects/installMM_downloads/main.py
dlg:
Control Identifiers:

SunAwtFrame - 'Setup'    (L710, T345, R1210, B735)
['Setup', 'SunAwtFrame', 'SetupSunAwtFrame']
child_window(title="Setup", class_name="SunAwtFrame")
Traceback (most recent call last):
  File "C:\Users\John\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pywinauto\application.py", line 250, in __resolve_control
    ctrl = wait_until_passes(
  File "C:\Users\John\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pywinauto\timings.py", line 458, in wait_until_passes
    raise err
pywinauto.timings.TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/John/PycharmProjects/installMM_downloads/main.py", line 22, in <module>
    do_installs()
  File "C:/Users/John/PycharmProjects/installMM_downloads/main.py", line 18, in do_installs
    dlg['Next'].click()
  File "C:\Users\John\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pywinauto\application.py", line 379, in __getattribute__
    ctrls = self.__resolve_control(self.criteria)
  File "C:\Users\John\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pywinauto\application.py", line 261, in __resolve_control
    raise e.original_exception
  File "C:\Users\John\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pywinauto\timings.py", line 436, in wait_until_passes
    func_val = func(*args, **kwargs)
  File "C:\Users\John\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pywinauto\application.py", line 222, in __get_ctrl
    ctrl = self.backend.generic_wrapper_class(findwindows.find_element(**ctrl_criteria))
  File "C:\Users\John\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pywinauto\findwindows.py", line 87, in find_element
    raise ElementNotFoundError(kwargs)
pywinauto.findwindows.ElementNotFoundError: {'best_match': 'Next', 'top_level_only': False, 'parent': <win32_element_info.HwndElementInfo - 'Setup', SunAwtFrame, 2490776>, 'backend': 'win32'}

Process finished with exit code 1

这是我要单击的带有“下一步”的对话框:

【问题讨论】:

    标签: python pywinauto


    【解决方案1】:

    解决方法是不要试图找到按钮。

    我能够通过以下方式做我想做的事:

    keyboard.send_keys('{ENTER}')
    

    在选择所需选项时按回车键,就像我发布的对话框一样。并且:

    dlg.click_input(coords=(x, y))
    

    在其他情况下,在指定坐标处(相对于对话框,dlg)单击鼠标。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-05
      • 2014-11-16
      • 2017-02-20
      • 2019-01-24
      • 2019-05-31
      • 1970-01-01
      • 1970-01-01
      • 2017-08-18
      相关资源
      最近更新 更多