Search code examples
pywinauto

How to enter braces inside url in pywinauto


I am trying to enter url in pywinauto like this "D:\Eudora(07NOV2008).mbx" but it is skipping braces and entering like this "D:\Eudora07NOV2008.mbx", how i can fix this issue.


Solution

  • It's not clear from question, but it seems method .type_keys() was used. This method tries to parse special keys with a key name in {} braces (like {ENTER}), the full list is described in the keyboard module document. This method is useful for special keys combinations for any window and/or element. For the mentioned use case the code should look so:

    .type_keys(r'D:{\}Eudora{(}07NOV2008{)}.mbx', with_spaces=True)
    # the last argument tells the method to not skip spaces
    

    For raw text input the more appropriate method is .set_edit_text() that inputs the text as is. It doesn't support special keys parsing though.

    For some rare cases there is one more useful method .set_value() (UIA backend only).

    Win32 backend contains silent text input methods .send_chars() and .send_keystrokes() that don't require even putting element into focused state.

    Many of these methods are described in the Remote Execution Guide.