5

I'm using pywinauto to automation Click on some button on DiffDaff software.

My intention are:

  • Step 1: Open DiffDaff software

  • Step 2: Click 'About' button

    from pywinauto.application import Application
    
    app = Application.start("C:\Program Files\DiffDaff\DiffDaff.exe")
    
    app.About.Click()
    

But, I'm on stuck at step 2, and the console show error:

  File "build\bdist.win32\egg\pywinauto\application.py", line 238, in __getattr__
  File "build\bdist.win32\egg\pywinauto\application.py", line 788, in _resolve_control
pywinauto.findbestmatch.MatchError: Could not find 'About' in '['', u'DiffDaff - Compare Files, Folders And Web Pages', u'Internet Explorer_Hidden', u'DiffDaff - Compare Files, Folders And Web PagesDialog', 'Dialog']'

Where, '', u'DiffDaff - Compare Files, Folders And Web Pages', u'Internet Explorer_Hidden', u'DiffDaff - Compare Files, Folders And Web PagesDialog', 'Dialog' is the title of sotfware

Also, using the command 'app.dialogs.print_control_identifiers()' to know what exact position of 'About' button, there is the output:

Button - '&About'   (L750, T388, R834, B411)
    '&About' '&AboutButton' 'Button3'

But it's so difficult to understand the parameter as above (what/where is L750, T388,...) - Would you like to explain all the mean of parameters as above ?

And the way to perform 'Click' button ?

Thanks.

Little Chicken
  • 215
  • 2
  • 7
  • 19

1 Answers1

9

pywinauto requires 2-level hierarchy from Application object to control method. The structure of any call is

app.<DialogName>.<ControlName>.<method>(<params>)

In your case it should look like

app.Dialog.About.click()

If you need more realistic click, please use click_input() which moves cursor and clicks the control as user. click() only sends WM_CLICK and it's less reliable also.

print_control_identifiers() method prints the following information:

<ControlType> - '<Name a la WindowText>' (<rectangle>)
                possible names which are most likely useful for object attribute access

Mentioned code is equivalent to the following:

app.window(best_match='Dialog', top_level_only=True).child_window(best_match='About').click()

pywinauto simplifies such constructions by overriding __getattribute__ method.

Vasily Ryabov
  • 9,386
  • 6
  • 25
  • 78
  • Thanks, it works! I'd like to know "(L750, T388, R834, B411)" will create (-|-) - is that right. and what the meaning of " '&About' '&AboutButton' 'Button3'" – Little Chicken Jul 08 '14 at 01:38
  • '&About' is a real WindowText() of the button. 'Button' is FriendlyClassName(). All possible names for `__getattr__` method have 3 variants: '', '' and 'i' where _i_ is an index of control of such type. For example, you can identify first button by 'Button0' or 'Button1', second button name can be 'Button2', and so on. This is useful for cases when you don't have texts or they are the same. – Vasily Ryabov Jul 08 '14 at 09:14
  • "(L750, T388, R834, B411)" is an absolute screen rectangle of the control. L means "left", R - "right", etc. – Vasily Ryabov Jul 08 '14 at 09:19
  • What is this "Dialog".?does it refer to the title of the window,How do i find this.? – arihanth jain Apr 15 '20 at 07:46