How to click using pywinauto

Viewed 7067

I would like to use pywinauto to control an image processing software.

First, I need to click a specific area (which is used for image dragging) to pop up a windows for path input. See the first figure.

Then, I need to input a path and click the button "Select Folder". See the second figure.

I tried:

from pywinauto import Desktop, Application, mouse, findwindows
from pywinauto.keyboard import SendKeys

app = Application(backend='uia').start(r"C:\Program Files\Duplicate Photo Cleaner\DuplicatePhotoCleaner.exe")
app.connect(path="DuplicatePhotoCleaner.exe")
app.DuplicatePhotoCleaner.print_control_identifiers()

Control Identifiers:

Dialog - 'Duplicate Photo Cleaner'    (L440, T126, R1480, B915)
['Duplicate Photo Cleaner', 'Duplicate Photo CleanerDialog', 'Dialog']
child_window(title="Duplicate Photo Cleaner", control_type="Window")
   | 
   | TitleBar - ''    (L464, T129, R1472, B157)
   | ['', 'TitleBar']
   |    | 
   |    | Menu - 'System'    (L448, T134, R470, B156)
   |    | ['System', 'Menu', 'SystemMenu', 'System0', 'System1']
   |    | child_window(title="System", auto_id="MenuBar", control_type="MenuBar")
   |    |    | 
   |    |    | MenuItem - 'System'    (L448, T134, R470, B156)
   |    |    | ['System2', 'SystemMenuItem', 'MenuItem']
   |    |    | child_window(title="System", control_type="MenuItem")
   |    | 
   |    | Button - 'Minimize'    (L1333, T127, R1380, B157)
   |    | ['Minimize', 'Button', 'MinimizeButton', 'Button0', 'Button1']
   |    | child_window(title="Minimize", control_type="Button")
   |    | 
   |    | Button - 'Maximize'    (L1380, T127, R1426, B157)
   |    | ['Button2', 'Maximize', 'MaximizeButton']
   |    | child_window(title="Maximize", control_type="Button")
   |    | 
   |    | Button - 'Close'    (L1426, T127, R1473, B157)
   |    | ['CloseButton', 'Button3', 'Close']
   |    | child_window(title="Close", control_type="Button")

Can anyone help?

Thank you very much.

First screen

Screen after click

1 Answers

Looks like the + button where you need to click to get the window (shown in second figure) is ownerdrawn.

So, there is only one way to bring up the "Add folder to search" window: use click_input method by passing coordinates.

Once the window comes up, you can use the below code to set the value:

app.DuplicatePhotoCleaner.child_window(title="Folder:", auto_id="1152", control_type="Edit").set_text('Hello world') #or
app.DuplicatePhotoCleaner['Folder:Edit'].set_text('Hello world')


Application().connect(title='Add folder to search')...

Please go though pywinauto docs for further info.

Related