无法使pywinauto单击按钮

2024-03-29 10:01:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用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

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

Here is the dialog with the "Next" that I want to click


Tags: inpylibpackageslocalsetuplinesite
1条回答
网友
1楼 · 发布于 2024-03-29 10:01:49

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

我可以通过以下方式实现我的目标:

keyboard.send_keys('{ENTER}')

当所需选择被选中时,按enter键,就像我发布的对话框一样。以及:

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

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

相关问题 更多 >