Forum Discussion

prakash_vasudev's avatar
prakash_vasudev
Contributor
13 years ago

Difference in typing value with [Enter] and actual carriage return

When we type a string on notepad which contains [Enter] it types the enter key once. But when the actual carriage return character is passed in then it types enter key twice.



Why does TestObject.Keys(Keys) method types 2 times enter when the actual carriage return key is passed in?
  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Prakash,


     


    It would be great if you posted the full problematic line here.


     


    BTW, what TestComplete version are you using (Help | About...)? 


     

  • ThunduBeedi's avatar
    ThunduBeedi
    Occasional Contributor
    TestComplete version is 8.20





    Dim string = "line1[Enter]line2"



    Set TestObject = Sys.Process("notepad").Window("Notepad", "Untitled - Notepad", 1).Window("Edit", "", 1)



    TestObject.Keys(string)



    This will type line1, Enter key and line2.



    But, if instead of [Enter] if we use the actual character for Enter key which is \r\n or \n or \r, TestObject.Keys will type Enter key twice.





  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Thundu,


     


    Thanks for the example. Actually, this behavior is specific to the Keys method. It recognizes \r as Enter and \n as Ctrl+Enter. That's why when you type \r\n two enters will be typed. I recommend that you use the SetText method instead of Keys.


     


    @Prakash, if you were talking about \r\n, the SetText method will help you as well.


     

  • Tanya,



    SetText method documentation says "The SetText action sets the contents of an edit control, that is, replaces the previous contents with the specified text."



    In case if we already have a text in the edit control it will completly replaced by the new text and we may be loosing the earlier text. This might not be of help to us. We are using keys method so that we can enter text on the control without loosing earlier.
  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Prakash,


     


    This can be resolved in the following way:




    Dim string


    string = obj.wText


    obj.SetText(string&"new text")




     


    The SetText method is more powerful. It allows you to type some symbols indicated as hot keys in the Keys method (for example, [, !, etc.) in text controls.