Search code examples
pywinauto

pywinauto type_keys() won't send all keys


I'm doing some windows automation and I need to import a file into a tool using the 'Open' dialog. I have this code

 w_open_handle = pywinauto.findwindows.find_windows(title=u'Open', class_name='#32770')[0]
 w_open = app.window_(handle=w_open_handle)

 # Enter filename in edit box
 w_open['File &name'].type_keys("export.txt")

When I run this I notice that only the keys "rt.txt" get sent to the File Name edit box on the window. I've tried other names instead of "export.txt" but in every case the first few keys are not sent. I thought perhaps a small delay between opening the dialog and sending the keys would help, but to no avail.

Can anyone tell me what's going on here?

Python 3.4.5 (I need this version because of other package dependencies)

Windows 10


Solution

  • Possible effects of type_keys():

    • It calls .set_focus() inside.
    • Incorrect control can be found (it's easy to check with .draw_outline() method).

    More reliable method that sets the whole text is .set_text("...") which is available to specific control types only.