Reputation: 411
i have written selenium script to read value from excel and pass it to text field. I am facing below mentioned issue
First i have passed invalid values to text field through sendkeys(). in second time, i am sending correct values to field through sendkeys(). But it is appending to the previous value.
How I can clear previously entered value in text field and pass new value to same fields
Can anyone provide solution for this
Upvotes: 0
Views: 3159
Reputation: 47
This code should do the job in Java. Put it before you enter the second piece of text.
_driver.findElement(By.id/css/xpath("element")).clear();
Upvotes: 1
Reputation: 3438
element.clear
element.sendkeys(value)
if you want to make this a one line step which combines clear and sendkeys, then you have many options, some dependent on the language you are using.
eg.
create a helper method which takes element and value
extend Element class and create a new method called Setvalue
Overwrite the existing sendkeys with a new method which calls clear first
Each of these have pros and cons and may be dependent on the language you use
Upvotes: 1