Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium WebDriver: I want to overwrite value in field instead of appending to it with sendKeys using Java

In WebDriver, if I use sendKeys it will append my string to the value that already exists in the field. I can't clear it by using clear() method because the second I do that, the webpage will throw an error saying that it has to be between 10 and 100. So I can't clear it or an error will be thrown before I can put in the new value using sendKeys, and if I sendKeys it just appends it to the value already there.

Is there anything in WebDriver that lets you overwrite the value in the field?

like image 318
True_Blue Avatar asked Jul 14 '10 19:07

True_Blue


People also ask

How do I enter values in field without sendKeys?

We can input text in the text box without the method sendKeys with thehelp of the JavaScript Executor. Selenium executes JavaScript commands with the help of the executeScript method. The JavaScript command to be run is passed as parameter to the method.

How do you overwrite the current input value in the editable field on page in Selenium?

To overwrite a value, we shall first select it with CTRL+A keys and then pass the new value. Thus, Keys. CONTROL, A and the new value are passed as parameters to the Keys.


1 Answers

You can also clear the field before sending it keys.

element.clear() element.sendKeys("Some text here") 
like image 164
Tim Banks Avatar answered Oct 09 '22 07:10

Tim Banks