!!

Welcome to Selenium Webdriver Forum

As a web user you can read and search through forum content. Once you have registered and signed you can post topics, post replies, set up watch lists, modify forum settings, and use private messaging.

Author Topic: How to clear value of a text box?  (Read 5209 times)

tester_wasi

  • Web User
How to clear value of a text box?
« on: July 26, 2012, 03:10:56 PM »
Hi..
I want to delete default value of a textbox to enter new value but I am not getting how to do that...
I was thinking to use CTRL+a and then DELETE but not sure how to do this...

Thanks in advance...

Corey_G

  • Web User
Re: How to clear value of a text box?
« Reply #1 on: July 26, 2012, 03:11:14 PM »
textbox WebElement has a .clear() method.

--------------------
Corey Goldberg
Homepage: goldb.org
Twitter: twitter.com/cgoldberg
Google+: gplus.to/cgoldberg

Carrying_Smiles

  • Web User
Re: How to clear value of a text box?
« Reply #2 on: July 26, 2012, 03:11:25 PM »
Are u using webdrivers for locating the element.

If yes u can use the .clear() method as mentioned by Corey.

--------------------
Thanks,
Ganesh,
Too much Reusability leads to complexity!!

Selenium Webdriver

Re: How to clear value of a text box?
« Reply #2 on: July 26, 2012, 03:11:25 PM »

RMKMR

  • Web User
Re: How to clear value of a text box?
« Reply #3 on: July 26, 2012, 03:11:38 PM »
what corey and carriying_smiles says is absolutely correct for clearing values in textbox or editfield in selenium webdriver.

Syntax:
 driver.findElement("locator").clear();

* locator - in locator you have to pass the locator of the element.

tester_wasi

  • Web User
Re: How to clear value of a text box?
« Reply #4 on: July 26, 2012, 03:12:02 PM »
Thanks everyboy, I tried .clear()but its not working, as described above i used webdriver junit4... this is what I did

driver.findElement(By.id("coe_7678e3c1c1636310VgnVCM1000000ddb42c7____")).clear();

did i do anything wrong???

fenec

  • Web User
Re: How to clear value of a text box?
« Reply #5 on: July 26, 2012, 03:12:17 PM »
hello,

you are correct, check if you have chosen the right element "coe_7678e3c1c1636310VgnVCM1000000ddb42c7____"

try the following:
driver.findElement(By.id("coe_7678e3c1c1636310VgnVCM1000000ddb42c7____")).sendKeys("hello");
check if hello is properly written in the element with id="coe_7678e3c1c1636310VgnVCM1000000ddb42c7____"

thank you.

Carrying_Smiles

  • Web User
Re: How to clear value of a text box?
« Reply #6 on: July 26, 2012, 03:12:30 PM »
Do check if this works!!! I used Xpath, but not sure if this works on your AUT

WebElement inputElement= driver.findElement(By.xpath("//input[contains(@id,'coe_7678e3c1c1636310VgnVCM1000000ddb42c7')]"));

inputElement.sendKeys("hello");

inputElement.clear();

--------------------
Thanks,
Ganesh,
Too much Reusability leads to complexity!!

tester_wasi

  • Web User
Re: How to clear value of a text box?
« Reply #7 on: July 26, 2012, 03:12:46 PM »
Thanks for your responses, now i got the problem selenium is not able identify locator... even with Selenium IDE when I use verifyElement command, the test is getting failed and this problem is with all text fields in the page... I have used all the possible locator values like id, css, dom, x-path but results the same... any suggestions?

Carrying_Smiles

  • Web User
Re: How to clear value of a text box?
« Reply #8 on: July 26, 2012, 03:13:10 PM »
Can u post the sample html for the input text field on this page!!

--------------------
Thanks,
Ganesh,
Too much Reusability leads to complexity!!

 

Related Topics

  Subject / Started by Replies Last post
2 Replies
1090 Views
Last post April 02, 2012, 08:08:31 PM
by bis
7 Replies
2840 Views
Last post April 10, 2012, 10:42:39 PM
by Daniel Wagner-Hall
1 Replies
1218 Views
Last post May 17, 2012, 08:04:47 PM
by Željko Filipin
6 Replies
1072 Views
Last post July 04, 2012, 04:22:37 PM
by Rovin
4 Replies
1454 Views
Last post July 26, 2012, 03:10:24 PM
by Carrying_Smiles
6 Replies
2690 Views
Last post January 07, 2013, 09:30:52 PM
by smani
0 Replies
1258 Views
Last post October 20, 2013, 10:57:48 PM
by shirinmd