clear text field using DELETE or BACK SPACE key

3,332 views
Skip to first unread message

amit dobriyal

unread,
Mar 6, 2016, 1:51:43 PM3/6/16
to Selenium Users
Hi ,
I am trying to clear a text field using below action,
emailField.sendKeys("gmail.com");
// clear the text entered
emailField.sendKeys(Keys.CONTROL,"a",Keys.DELETE);

In above code, last line only selects the text , it is not deleting it, but if i separate the actions it works.

emailField.sendKeys(Keys.CONTROL,"a");
emailField.sendKeys(Keys.DELETE);

Jegadeesh mani

unread,
Mar 9, 2016, 5:20:20 AM3/9/16
to seleniu...@googlegroups.com

Hi,

Use it clear script command

driver.findelement(I'd).clear

Thanks
Jegadeesh

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/2833e0d2-84bf-4780-b63d-c61ac4c4b21f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

swapnil khute

unread,
May 8, 2019, 9:50:14 AM5/8/19
to Selenium Users
Hi Amit,

You may use the below command -

emailField.sendKeys(Keys.chord(Keys.CONTROL,"a",Keys.DELETE));

I hope this will resolve your problem.


sravan palleti

unread,
May 8, 2019, 10:46:21 AM5/8/19
to seleniu...@googlegroups.com
Swapnil, You should be passing string to 'Sendkeys' method.

What is your business need? for using this -> Keys.chord(Keys.CONTROL,"a",Keys.DELETE)

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages