TestProject Forum
Powered by leading experts in the test automation community

Delete random number of characters from textbox in selenium

I have a textbox to run tests on and i need to delete a random number of characters from the string
so if i have a string: “Hello world”

I would like to delete 2 or 3 of last characters

What is the best way to do this in selenium ?

Just make a for loop with your random number and send backspace key to the element in question:

for(int i = 0; I < random; i++) {
    element.sendKeys(Keys.BACK_SPACE);
}