14

Using Selenium how to delete single characters from a textbox using Selenium?

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

Ex: ABCD to AB

5

If you are using Java, try this to delete one character:

element.sendKeys("\u0008");
| improve this answer | |
  • Thanks a lot. But what this "\u0008" is? ASCII value of backspace is 0x08 – smriti Jun 24 '11 at 12:31
  • 1
    "\u0008" is Unicode for the backspace character. The sendKeys method takes a CharacterSequence as input. "\u0008" is a CharacterSequence; 0x08 is an integer instead of a CharacterSequence. Moreover, you cannot use 0x notation to encode characters within a Java string. – user246 Jun 24 '11 at 13:07
13

While using the ASCII valid (\u008) is valid, there are already defines for this which makes your code more readable, as such:

element.sendKeys(Keys.BACK_SPACE);

For a list of the key names, there's some official documentation.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.