15

Through selenium. how to delete contents from textbox.

I have to delete the last 2 characters from text box using selenium command.

Ex.ABCD to AB.

smriti
  • 1,124
  • 5
  • 14
  • 35

5 Answers5

17

Try this -

selenium.type("text_box_object", "ABCD");
selenium.typeKeys("text_box_object", "\b");
selenium.typeKeys("text_box_object", "\b");
rs79
  • 2,311
  • 2
  • 33
  • 39
4

The keyPress event of selenium can be helpful:

selenium.sendKeys("text1", "ABCD");
selenium.sendKeys("text1", "\b");
selenium.sendKeys("text1", "\b");

This will Click Backspace key twice.

2

For firefox, the backspace event works only if you setCursorPosition at the END of the text in the textarea, otherwise the typeKeys event will type at the begining of the text.

2

Read the current value and store it as a variable. Then 'Type' out the value that you want in the target field (using a substring of the stored value).

Peter Bernier
  • 8,038
  • 6
  • 38
  • 53
  • Thanks a lot @Peter. This is good option,but I want to know is any selenium cmd available to delete the character from text box. – smriti Jun 24 '11 at 08:49
1

Click onto it, hit end key and backspace twice

Orn Kristjansson
  • 3,435
  • 4
  • 26
  • 40
  • @ Orn I need to do it through selenium command .is there any way to recognize the End key, Backspace key trough selenium as I know keyPressNative() cmd will help? Thanks – smriti Jun 23 '11 at 06:31