4

I'm trying to automate a windows application using pywinauto. I can select the menu and open the "open file window". I need to wait for this window to appear and then set focus to that window and click some buttons.

For some reason is not working.

def open_file():
    return pywinauto.findwindows.find_windows(best_match=u'Open File', class_name='#32770')[0]
pywinauto.timings.WaitUntilPasses(20, 0.5,open_file)
print('wait for window')
open_file.SetFocus()

When I try to run this it says that open_file doesn't have a SetFocus option.

I'm a beginner in pywinauto and I'm pretty sure that this is something easy to fix but I don't know how :/

Tobias Kienzler
  • 25,759
  • 22
  • 127
  • 221
Tiago São José
  • 292
  • 3
  • 5
  • 12

1 Answers1

5

open_file is a function. It has no such method. It is much simpler to use Application object to wait dialog.

OpenDialog = pwa_app.window(best_match=u'Open', class_name='#32770').wait('visible', timeout=20, retry_interval=0.5)
OpenDialog.set_focus()

Low-level functions like wait_until_passes are already encapsulated inside wait and wait_not methods of class WindowSpecification.


Even more simple code should work:

pwa_app.OpenDialog.wait('visible', timeout=20)
pwa_app.OpenDialog.set_focus()
Vasily Ryabov
  • 9,386
  • 6
  • 25
  • 78
  • Did you check this code? As I could see in previous question, you don't call method `start_('your.exe')` or `connect_(path='exe_name')` for `Application` object. If you do that, many things will become simpler. – Vasily Ryabov Feb 18 '15 at 11:43