Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

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

share|improve this question

2 Answers 2

up vote 4 down vote accepted

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

element.sendKeys("\u0008");
share|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
    
Thanks a lot @user246 –  smriti Jun 27 '11 at 8:22

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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