I am trying to use pywinauto
to run a large number of exe
files that add items to an existing application. The exe
file starts as expected, and the dialog of interest (below) appears, but I cannot get the "Next" button in the dialog clicked. Looks like pywinauto
cannot find the "Next" button. An ideas how to get his to work? Here is my code:
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()
Here is the output log:
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
And Here is the dialog with the "Next" that I want to click:
The solution is to not try to find the buttons.
I was able to do what I wanted by using:
keyboard.send_keys('{ENTER}')
to hit the enter key for cases when the desired selection is selected, as it is for the dialog that I posted. And:
dlg.click_input(coords=(x, y))
to click the mouse at the specified coordinates (relative to the dialog, dlg
) for other cases.