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?
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.
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.
You can also clear the field before sending it keys.
element.clear() element.sendKeys("Some text here")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With