Forum Discussion

jaredjamieson's avatar
jaredjamieson
Occasional Contributor
2 years ago
Solved

Keys method does not input the entire string

I am able to use the method:

 

    on_screen_element.keys("1234567890");

 

Most of the time, with smaller strings, this correctly simulates pressing each key in the string.  With strings that are generally 'longer' such as the example, the output ends up being:

 

    134567890

 

This ends up completely missing the 2nd element of the string consistently.  When checking the logs, it states:

 

    The keystrokes '1234567890' were sent to the control.

 

I have attempted to resolve this issue by doing:

 

    for (letter in string)

        on_screen_element.keys(letter);

 

This results in the same issue.  Any help would be greatly appreciated!  Thank you all in advance.  

 

  • Marsha_R's avatar
    Marsha_R
    2 years ago

    I would go ahead and try the upgrade.

9 Replies

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3

    I've never seen a problem with Keys before, even with very long strings.

     

    If you aren't on the latest version of TestComplete, I would try updating and see if that fixes it.

     

    If you are on the latest version already, I would contact Support directly about this. Here's the link:

    https://support.smartbear.com/testcomplete/message/

  • tvklovesu's avatar
    tvklovesu
    Frequent Contributor

    Just wondering, can't you use SetText() instead of Keys(). SetText works seamlessly. 

    • Marsha_R's avatar
      Marsha_R
      Champion Level 3

      tvklovesu wrote:

      Just wondering, can't you use SetText() instead of Keys(). SetText works seamlessly. 


      lol I have found it to be the exact opposite - SetText doesn't work where I need it and Keys always does

      • jaredjamieson's avatar
        jaredjamieson
        Occasional Contributor
        That is what I have noticed. I cannot use SetText() on the same objects I can use Keys().
  • jaredjamieson's avatar
    jaredjamieson
    Occasional Contributor

    .Keys() appears to have been working now.  I did not go through with the update as mentioned above.  As I have not changed anything, I assume I was just having a random bug that is no longer in affect.  I'll accept the update as the solution since that would make the most sense if this inconsistency was still present.  

    • tvklovesu's avatar
      tvklovesu
      Frequent Contributor

      I finally found why SetText() is not available few times and its available at other times. If the object you are using has element tag as input then you will see the setText() and if that objects tag is something like span, div or anything else other than input then you can't use setText() and in that case we left with only option to use Keys method.