Forum Discussion

kjadhavkunal's avatar
kjadhavkunal
Contributor
9 years ago

What method do we use to clear a text from textbox on a same page in Jscript?

- I am using Jscript language for automation scripting

- It is appending a next text but I want to clear other fields before writing any text on a same page.

 

  • NisHera's avatar
    NisHera
    Valued Contributor

    may be you are using Keys('your text')

    before that you can use

     SetText('')

     

    • kjadhavkunal's avatar
      kjadhavkunal
      Contributor

      HI NisHera,

                   I have tried using SetTex("") method to clear textboxes. It worked out. But I also tried to use SetText("") and Keys("") methods for Textarea idealy it shoul work but it doesnt. Again it appends the text

      • joseph_michaud's avatar
        joseph_michaud
        Moderator

        Try using textarea.Keys("^a[BS]")

         

        If that doesn't work, see Alex Karas' solution here

         

  • william_roe's avatar
    william_roe
    Super Contributor

    kjadhavkunaljoseph_michaudNisHera Since moving the 11.31 we've had to use the value setter whenever the keys operation was used immediately after the SetText or we got the "object destroyed" message. There was a breaking change to how the SetText worked since 11.20.

    • Colin_McCrae's avatar
      Colin_McCrae
      Community Hero

      Personally, I like the solution @joseph_Michaud suggested

       

      Why? Because it's what the user would do. SetText is not.

       

      It also depends on application behaviour. Some applications will be set up to automatically highlight any text already there (to enable easy deletion) on detecting the user entering the field. Whether this is by clicking in, or tabbing in, or whatever. In which case, you may want to emulate that behaviour. By applying Keys or SetText straight to a field, you may not trigger activation/entry behaviour.

       

      (PS .... why do the user name links seldom work properly for me? What am I supposed to type to trigger them?)

      • william_roe's avatar
        william_roe
        Super Contributor

        Colin_McCrae wrote:

         

        (PS .... why do the user name links seldom work properly for me? What am I supposed to type to trigger them?)


        Colin_McCrae

        Are you entering '@" before the user name?