smriti
smriti

Reputation: 1144

Selenium: delete contents from a textbox

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.

Upvotes: 15

Views: 15737

Answers (5)

Roshan Bhuran
Roshan Bhuran

Reputation: 59

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.

Upvotes: 4

Bogdan Corpade
Bogdan Corpade

Reputation: 21

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.

Upvotes: 2

rs79
rs79

Reputation: 2321

Try this -

selenium.type("text_box_object", "ABCD");
selenium.typeKeys("text_box_object", "\b");
selenium.typeKeys("text_box_object", "\b");

Upvotes: 17

Peter Bernier
Peter Bernier

Reputation: 8069

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).

Upvotes: 2

Orn Kristjansson
Orn Kristjansson

Reputation: 3485

Click onto it, hit end key and backspace twice

Upvotes: 1

Related Questions