Selenium webdriver: element.clear() not clearing the textbox values sometimes

2.6k Views Asked by At

I want to clear a text box value which has default data as current time or current date. What I usually do is use element.clear() to clear the textbox and later use element.sendkeys() to enter my data. But now what happens is that in a single iteration, some times the above logic works and the data given is saved. But in some cases the text box value is not cleared and the date or time got saved as the default one. It happens randomly. The webdriver version is 2.46.0

1

There are 1 best solutions below

0
On

Try using a nice try\catch or if statement to verify the element.text attribute is blank before you sendkeys(). That should ensure the data is cleared before continuing and adding in new text.