Forum Discussion

googleid_118035's avatar
googleid_118035
Contributor
10 years ago
Solved

How to tell Testcomlpete to clear a value in text area.


Hi All,


 


I have a text area in web page and intially its contain some text.


So I have to insert a new text after removing exsisting text in the text area.


How can I do that?




....................

Thanks

Dev

6 Replies

  • Hi Dev



    Try using Textarea_Object.Keys("^a" & "[Del]"); without loop.



    Regards

    Kumar
  • Hi Dev,



    glad it was helpful. The only downside of this approach is that it does not emulate an actual user interaction. If you simply need to automate clearing of the field - go for it. But if you need to test that the field handles user input correctly then you better go for one of the Keys approaches mentioned above. This is because the field might have specific event handler functions attached ('onkeydown' for example) and that functions will not be called if you simply change the "value" property.

  • Hi All,



    I just try with following code, but its only delete last charaters only from the text area.




    Textarea_Object.Click();


    var var1 = Textarea_Object.contentText;


    var var2 = var1.length;


     


    for (i = 0; i < var2; i++){


    Textarea_Object.Keys("[BS]");


    }



    ..........................

    Thanks

    Dev

  • Depends what the text input is.



    Rather than sending a backspace, try sending an "escape" keypress. With many text inputs, that will clear the field.



    I suspect your loop sending backspaces is running too fast. Which is why you are only seeing one character being deleted. With loops like that, you often need to be careful that your keypresses, and what happens on screen, are properly synchronised.



    If you force a delay in the loop so that after each backspace, it waits until the text content shortens by 1, it would probably work.

  • Hi Stanislav,


     


    Thanks for the information.


    I just try with value property and its work, here is my code.


     


    Textarea_Object.Click();


    Textarea_Object.value = "";


     


     


     


    ..........................


    Thanks


    Dev