Search code examples
pywinauto

AttributeError: WindowSpecification class has no 'typekeys' method


I am new to Pywinauto and trying to click "ENTER" after I login to remote desktop application. The desktop window has an usage disclaimer with "OK" button and I can either press "ENTER" or mouse move to click "OK". Below is the code snippet and the error which I am getting.

rem_app = Application(backend="uia").connect(title_re='.*Remote desktop.*')
dlg_rem = rem_app.window(title_re='.*Remote desktop.*')
dlg_rem.set_focus()
dlg_rem.typekeys('{ENTER}')

Error: Traceback (most recent call last): File "", line 1, in File "C:\Python27\lib\site-packages\pywinauto\application.py", line 171, in call format(self.criteria[-1]['best_match'])) AttributeError: WindowSpecification class has no 'typekeys' method

I have also used the below by looking into other related stackoverflow questions:

  1. keyboard.sendkeys('{ENTER}')
  2. dlg_rem.sendkeys('{ENTER}')

Here's what print_control_identifiers() describes about the "OK" button.

   |    |    |    | Pane - ''    (L403, T360, R1671, B1320)
   |    |    |    | [u'3', 'Pane4']

   |    |    |    |    |
   |    |    |    |    | Pane - 'Input Capture Window'    (L403, T360, R1671, B1320)
   |    |    |    |    | [u'Input Capture Window', u'Input Capture WindowPane', 'Pane5']
   |    |    |    |    | child_window(title="Input Capture Window", control_type="Pane")

I would like to know on how to use sendkeys and mouse move to click "OK" for the above scenario in both cases.


Solution

  • Correct method name is .type_keys('{ENTER}'). It sets the focus to target window before typing.

    If you don't need auto-focus, just use keyboard.SendKeys('{ENTER}') without binding to any app (0.6.3. will have keyboard.send_keys alias that fits into PEP8 guidelines).

    P.S. Don't recommend to automate anything by Remote Desktop (with any tool) because RDP doesn't expose UI accessibility features to local machine. Just copy the script to remote machine and run it there.

    If you need several remote machines running GUI automation tasks simultaneously, check these answers for more details: